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

Glossary Item Box

Servers a dual-role, it can prevent an aggregated stream from disposing, or it can manage other objects that need to be disposed when the stream is disposed.

Syntax

Visual Basic (Declaration) 
Public Class DisposingStream 
   Inherits AggregateStream
C# 
public class DisposingStream : AggregateStream 

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?

Inheritance Hierarchy

System.Object
   System.MarshalByRefObject
      System.IO.Stream
         CSharpTest.Net.IO.AggregateStream
            CSharpTest.Net.IO.DisposingStream

Requirements

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

See Also

Generated with Document! X 2011 by Innovasys