-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProgram.cs
More file actions
53 lines (44 loc) · 1.69 KB
/
Program.cs
File metadata and controls
53 lines (44 loc) · 1.69 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
using System.Text.Json;
var jsonPath = Path.Combine(Directory.GetCurrentDirectory(), "gitversion.json");
var outputPath = Path.Combine(Directory.GetCurrentDirectory(),
"GitVersionInformation.g.cs");
var json = JsonDocument.Parse(File.ReadAllText(jsonPath)).RootElement;
using var writer = new StreamWriter(outputPath);
writer.WriteLine("internal static class GitVersionInformation");
writer.WriteLine("{");
foreach (var property in json.EnumerateObject()) {
var name = property.Name;
var value = property.Value;
string line;
switch (value.ValueKind) {
case JsonValueKind.String:
line =
$" public const string {name} = \"{value.GetString()?.Replace("\"", "\\\"")}\";";
break;
case JsonValueKind.Number:
if (value.TryGetInt32(out var intVal))
line = $" public const int {name} = {intVal};";
else if (value.TryGetInt64(out var longVal))
line = $" public const long {name} = {longVal}L;";
else if (value.TryGetDouble(out var dblVal))
line = $" public const double {name} = {dblVal};";
else
continue; // Skip if unknown number type
break;
case JsonValueKind.True:
case JsonValueKind.False:
line =
$" public const bool {name} = {value.GetBoolean().ToString().ToLowerInvariant()};";
break;
case JsonValueKind.Null:
// No const nulls in C#, so use string.Empty or 0 as appropriate — or skip
line = $" public const string {name} = \"\";"; // Assuming string type
break;
default:
// Skip unexpected structures like arrays/objects
line = $" // {name} has unsupported type and is omitted";
break;
}
writer.WriteLine(line);
}
writer.WriteLine("}");