Visual Basic (Declaration) | |
---|---|
Public Function New() |
C# | |
---|---|
public DisposingList() |
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.NET | Copy 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) |
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
Reference
DisposingList ClassDisposingList Members
Overload List