Skip to content

Instantly share code, notes, and snippets.

@mntone
Created February 6, 2015 07:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mntone/cc7ed8277ef7a6567531 to your computer and use it in GitHub Desktop.
Save mntone/cc7ed8277ef7a6567531 to your computer and use it in GitHub Desktop.
Dispose を回避する Stream (MIT license)
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