Added ability to get a filename only by passing 'null' to constructor. Fixed disposal so can't error.

pull/83/head
David Hall 2019-08-20 10:20:19 -06:00
parent b7cedf436f
commit 6e70fc0b19
1 changed files with 8 additions and 2 deletions

View File

@ -15,7 +15,11 @@ namespace Vanara.PInvoke.Tests
public TempFile(string contents = tmpstr)
{
FullName = Path.GetTempFileName(); File.WriteAllText(FullName, contents);
FullName = Path.GetTempFileName();
if (contents is null)
File.Delete(FullName);
else
File.WriteAllText(FullName, contents);
}
public string FullName { get; }
@ -23,7 +27,9 @@ namespace Vanara.PInvoke.Tests
void IDisposable.Dispose()
{
hFile?.Dispose(); File.Delete(FullName);
hFile?.Dispose();
if (File.Exists(FullName))
File.Delete(FullName);
}
}
}