Files
git-tfs/GitTfs/Util/TemporaryFile.cs
2012-05-21 10:53:22 -04:00

40 lines
865 B
C#

using System;
using System.Diagnostics;
using System.IO;
namespace Sep.Git.Tfs.Util
{
public class TemporaryFile : IDisposable
{
public TemporaryFile() : this(System.IO.Path.GetTempFileName())
{
}
public TemporaryFile(string path)
{
Path = path;
}
public string Path { get; private set; }
public static implicit operator string(TemporaryFile f)
{
return f.Path;
}
public void Dispose()
{
try
{
if (Path != null && File.Exists(Path))
File.Delete(Path);
Path = null;
}
catch (Exception e)
{
Trace.WriteLine("[TemporaryFile] Unable to remove " + Path + ": " + e);
}
}
}
}