forked from sbozzie/test-intel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTempFile.cs
More file actions
55 lines (45 loc) · 1.55 KB
/
Copy pathTempFile.cs
File metadata and controls
55 lines (45 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Globalization;
using System.IO;
namespace PleaseIgnore.IntelMap.Tests {
/// <summary>
/// Creates a new file that is automatically deleted when this class
/// is disposed.
/// </summary>
internal sealed class TempFile : IDisposable {
private readonly string fileName;
public TempFile() : this(null, null) {
}
public TempFile(TempDirectory directory) : this(null, directory) {
}
public TempFile(string baseName) : this(baseName, null) {
}
public TempFile(string baseName, TempDirectory directory) {
this.fileName = Path.Combine(
(directory != null)
? directory.FullName
: System.IO.Path.GetTempPath(),
(baseName ?? "temp") + DateTime.UtcNow.ToString(
"'_'yyyyMMdd'_'HHmmss'.txt'",
CultureInfo.InvariantCulture));
}
public FileInfo FileInfo {
get { return new FileInfo(this.fileName); }
}
public string FullName {
get { return this.fileName; }
}
public string Name {
get { return Path.GetFileName(this.fileName); }
}
public FileStream Open(FileMode mode, FileAccess access, FileShare share) {
return new FileStream(this.fileName, mode, access, share);
}
public void Dispose() {
try {
File.Delete(fileName);
} catch (IOException) {
}
}
}
}