Update 10.21 to match book
MODIFY
src/Chapter10/Listing10.21.ResourceCleanupWithIDisposable.cs
src/Chapter10/Listing10.21.ResourceCleanupWithIDisposable.cs
public TemporaryFileStream()
: this(Path.GetTempFileName()) { }
-
-
~TemporaryFileStream()
{
Dispose(false);
}
- public FileStream Stream { get; }
- public FileInfo File { get; }
-
- protected void Close()
- {
- Dispose();
- }
+ public FileStream? Stream { get; private set; }
+ public FileInfo? File { get; private set; }
#region IDisposable Members
public void Dispose()
{
Dispose(true);
- // Turn off calling the finalizer
+ //unregister from the finalization queue.
System.GC.SuppressFinalize(this);
}
#endregion
{
Stream?.Dispose();
}
+ try
+ {
File?.Delete();
}
+ catch (IOException exception)
+ {
+ Console.WriteLine(exception);
+ }
+ Stream = null;
+ File = null;
+ }
}
}
\ No newline at end of file

Update 10.21 to match book