Created
February 6, 2015 07:40
-
-
Save mntone/cc7ed8277ef7a6567531 to your computer and use it in GitHub Desktop.
Dispose を回避する Stream (MIT license)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
namespace XXX | |
{ | |
internal class NonClosingStreamWrapper: Stream | |
{ | |
private Stream _stream; | |
public NonClosingStreamWrapper( Stream stream ) | |
{ | |
this._stream = stream; | |
} | |
protected override void Dispose( bool disposing ) | |
{ | |
if( disposing ) | |
{ | |
this._stream = null; | |
} | |
} | |
public override bool CanRead | |
{ | |
get { return this._stream.CanRead; } | |
} | |
public override bool CanSeek | |
{ | |
get { return this._stream.CanSeek; } | |
} | |
public override bool CanWrite | |
{ | |
get { return this._stream.CanWrite; } | |
} | |
public override void Flush() | |
{ | |
this._stream.Flush(); | |
} | |
public override long Length | |
{ | |
get { return this._stream.Length; } | |
} | |
public override long Position | |
{ | |
get | |
{ | |
return this._stream.Position; | |
} | |
set | |
{ | |
this._stream.Position = value; | |
} | |
} | |
public override int Read( byte[] buffer, int offset, int count ) | |
{ | |
return this._stream.Read( buffer, offset, count ); | |
} | |
public override long Seek( long offset, SeekOrigin origin ) | |
{ | |
return this._stream.Seek( offset, origin ); | |
} | |
public override void SetLength( long value ) | |
{ | |
this._stream.SetLength( value ); | |
} | |
public override void Write( byte[] buffer, int offset, int count ) | |
{ | |
this._stream.Write( buffer, offset, count ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment