Files
git-tfs/GitTfs/Util/TemporaryFile.cs
T
Philippe Miossec b18fea8b6a Formatting code using CodeFormatter
CodeFormatter.exe /rule-:FieldNames /nounicode /nocopyright .\GitTfs.sln
2016-10-18 22:10:22 +02:00

40 lines
858 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);
}
}
}
}