Created
September 8, 2015 08:05
-
-
Save poulfoged/df026e8b12e19122a743 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class TemporaryDirectory : IDisposable | |
{ | |
private readonly DirectoryInfo _directoryInfo; | |
private bool _disposed; | |
public TemporaryDirectory() | |
{ | |
_directoryInfo = new DirectoryInfo(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"))); | |
_directoryInfo.Create(); | |
} | |
public DirectoryInfo Info | |
{ | |
get { return _directoryInfo; } | |
} | |
protected virtual void Dispose(bool disposing) | |
{ | |
if (_disposed) | |
return; | |
try | |
{ | |
_directoryInfo.Delete(true); | |
} | |
catch (Exception ex) | |
{ | |
Debug.WriteLine(ex); | |
} | |
_disposed = true; | |
} | |
~TemporaryDirectory() | |
{ | |
Dispose(false); | |
} | |
public void Dispose() | |
{ | |
Dispose(true); | |
GC.SuppressFinalize(this); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment