-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPreSharp.cs
39 lines (32 loc) · 1.28 KB
/
PreSharp.cs
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
using System.Collections.Generic;
using System.IO;
public static class PreSharp {
private static TextWriter writer;
public static TextWriter Writer { get { return writer; } }
internal static readonly List<string> CompileGeneratedFiles = new List<string>();
internal static readonly List<string> EmbeddedResourceGeneratedFiles = new List<string>();
internal static bool HasOutputs { get; private set; }
private static string currentFile;
public enum OutputType { Compile, EmbeddedResource, None }
public static void Flush() {
if (currentFile != null) {
string output = writer.ToString();
if (!File.Exists(currentFile) || output != File.ReadAllText(currentFile)) {
File.WriteAllText(currentFile, output);
}
currentFile = null;
writer = null;
}
}
public static void SetOutput(string outputFile, OutputType outputType) {
Flush();
currentFile = outputFile;
writer = new StringWriter();
if (outputType == OutputType.Compile) {
CompileGeneratedFiles.Add(outputFile);
} else if (outputType == OutputType.EmbeddedResource) {
EmbeddedResourceGeneratedFiles.Add(outputFile);
}
HasOutputs = true;
}
}