CSharpTest.Net
DisposingStream Constructor
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.IO Namespace > DisposingStream Class : DisposingStream Constructor

stream

Glossary Item Box

Create the wrapper on the provided stream, add disposables via WithDosposeOf(...)

Syntax

Visual Basic (Declaration) 
Public Function New( _
   ByVal stream As Stream _
)
C# 
public DisposingStream( 
   Stream stream
)

Parameters

stream

Example

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.NETCopy 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?

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys