Visual Basic (Declaration) | |
---|---|
Public Function WithDisposeOf( _ ByVal disposable As IDisposable _ ) As DisposingStream |
C# | |
---|---|
public DisposingStream WithDisposeOf( IDisposable disposable ) |
Parameters
- disposable
Library/Library.Test/TestStreams.cs
C# | Copy Code |
---|---|
DisposableFlag f1 = new DisposableFlag(); DisposableFlag f2 = new DisposableFlag(); Assert.IsFalse(f1.Disposed || f2.Disposed); Stream ms1 = new DisposingStream(new MemoryStream(Encoding.ASCII.GetBytes("Hello"))).WithDisposeOf(f1); Stream ms2 = new DisposingStream(new MemoryStream(Encoding.ASCII.GetBytes("There"))).WithDisposeOf(f2); using (Stream cs = new CombinedStream(ms1, ms2)) { } Assert.IsTrue(f1.Disposed && f2.Disposed);//even though not read, we did dispose? |
VB.NET | Copy Code |
---|---|
Dim f1 As New DisposableFlag() Dim f2 As New DisposableFlag() Assert.IsFalse(f1.Disposed OrElse f2.Disposed) Dim ms1 As Stream = New DisposingStream(New MemoryStream(Encoding.ASCII.GetBytes("Hello"))).WithDisposeOf(f1) Dim ms2 As Stream = New DisposingStream(New MemoryStream(Encoding.ASCII.GetBytes("There"))).WithDisposeOf(f2) Using cs As Stream = New CombinedStream(ms1, ms2) End Using Assert.IsTrue(f1.Disposed AndAlso f2.Disposed) 'even though not read, we did dispose? |
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
Reference
DisposingStream ClassDisposingStream Members
Used By
Stream AsymmetricKey.Encrypt(Stream)Stream AsymmetricKey.Decrypt(Stream)
Stream AESCryptoKey.Encrypt(Stream)
Stream AESCryptoKey.Decrypt(Stream)
Stream PasswordKey.Encrypt(Stream)
Stream PasswordKey.Decrypt(Stream,Salt.Size)