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

Glossary Item Box

Disposes of each element in the collection when the collection is disposed.

Object Model

DisposingList ClassIDisposable Interface

Syntax

Visual Basic (Declaration) 
Public Class DisposingList 
   Inherits CSharpTest.Net.Collections.DisposingList(Of IDisposable)

Example

Library/Library.Test/TestReplaceFile.cs

C#Copy Code
string path;
using(DisposingList l = new DisposingList())
{
    TempFile ftarget = new TempFile();
    ftarget.Delete();

    l.Add(ftarget);
    TempFile fbigone = TempFile.Attach(String.Format("{0}.~{1:x4}", ftarget.TempPath, 0x10008 - 25));
    fbigone.Create().Dispose();
    Assert.IsTrue(fbigone.Exists);
    l.Add(fbigone);
    path = ftarget.TempPath;

    string tmpName;
    Dictionary<string, object> names = new Dictionary<string,object>(StringComparer.OrdinalIgnoreCase);

    for( int i=0; i < 25; i++ )
    {
        Stream s = ReplaceFile.CreateDerivedFile(ftarget.TempPath, out tmpName);
        l.Add(TempFile.Attach(tmpName));
        l.Add(s);
        names.Add(tmpName, null);
    }
    
    fbigone.Delete();
    Assert.AreEqual(25, Directory.GetFiles(Path.GetDirectoryName(path), Path.GetFileName(path) + "*").Length);
}
Assert.AreEqual(0, Directory.GetFiles(Path.GetDirectoryName(path), Path.GetFileName(path) + "*").Length);
VB.NETCopy Code
Dim path As String
Using l As New DisposingList()
    Dim ftarget As New TempFile()
    ftarget.Delete()

    l.Add(ftarget)
    Dim fbigone As TempFile = TempFile.Attach([String].Format("{0}.~{1:x4}", ftarget.TempPath, &H10008 - 25))
    fbigone.Create().Dispose()
    Assert.IsTrue(fbigone.Exists)
    l.Add(fbigone)
    path = ftarget.TempPath

    Dim tmpName As String
    Dim names As New Dictionary(Of String, Object)(StringComparer.OrdinalIgnoreCase)

    Dim i As Integer = 0
    While i < 25
        Dim s As Stream = ReplaceFile.CreateDerivedFile(ftarget.TempPath, tmpName)
        l.Add(TempFile.Attach(tmpName))
        l.Add(s)
        names.Add(tmpName, Nothing)
        System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
    End While

    fbigone.Delete()
    Assert.AreEqual(25, Directory.GetFiles(Path.GetDirectoryName(path), Path.GetFileName(path) + "*").Length)
End Using
Assert.AreEqual(0, Directory.GetFiles(Path.GetDirectoryName(path), Path.GetFileName(path) + "*").Length)

Inheritance Hierarchy

System.Object
   System.Collections.Generic.List<T>
      CSharpTest.Net.Collections.DisposingList<T>
         CSharpTest.Net.Collections.DisposingList

Requirements

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

See Also

Generated with Document! X 2011 by Innovasys