Fix compiler warning and Versioning Namespace

This commit is contained in:
MSWS
2025-07-30 06:08:00 -07:00
parent b44c73cf87
commit 9a66dbccf9
2 changed files with 9 additions and 13 deletions

View File

@@ -9,9 +9,8 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Locale\Locale.csproj"/>
<ProjectReference Include="..\..\Locale\Locale.csproj" />
<ProjectReference Include="..\API\API.csproj"/>
<ProjectReference Include="..\Locale\Locale.csproj"/>
<ProjectReference Include="..\Plugin\Plugin.csproj"/>
</ItemGroup>

View File

@@ -8,10 +8,8 @@ var json = JsonDocument.Parse(File.ReadAllText(jsonPath)).RootElement;
using var writer = new StreamWriter(outputPath);
writer.WriteLine("namespace GitVersion");
writer.WriteLine("internal static class GitVersionInformation");
writer.WriteLine("{");
writer.WriteLine(" internal static class GitVersionInformation");
writer.WriteLine(" {");
foreach (var property in json.EnumerateObject()) {
var name = property.Name;
@@ -22,35 +20,34 @@ foreach (var property in json.EnumerateObject()) {
switch (value.ValueKind) {
case JsonValueKind.String:
line =
$" public const string {name} = \"{value.GetString()?.Replace("\"", "\\\"")}\";";
$" public const string {name} = \"{value.GetString()?.Replace("\"", "\\\"")}\";";
break;
case JsonValueKind.Number:
if (value.TryGetInt32(out var intVal))
line = $" public const int {name} = {intVal};";
line = $" public const int {name} = {intVal};";
else if (value.TryGetInt64(out var longVal))
line = $" public const long {name} = {longVal}L;";
line = $" public const long {name} = {longVal}L;";
else if (value.TryGetDouble(out var dblVal))
line = $" public const double {name} = {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()};";
$" 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 = $" // {name} is null and omitted";
line = $" // {name} is null and omitted";
break;
default:
// Skip unexpected structures like arrays/objects
line = $" // {name} has unsupported type and is omitted";
line = $" // {name} has unsupported type and is omitted";
break;
}
writer.WriteLine(line);
}
writer.WriteLine(" }");
writer.WriteLine("}");