diff --git a/ConfigGenerator.Tests/TestFiles/appsettings.json b/ConfigGenerator.Tests/TestFiles/appsettings.json index a241754..879cb23 100644 --- a/ConfigGenerator.Tests/TestFiles/appsettings.json +++ b/ConfigGenerator.Tests/TestFiles/appsettings.json @@ -10,8 +10,12 @@ "DuplicateEntryOnlyShowsOnce": false, "IntValue": 1, "DoubleValue": 2.2, + "LongValue": 9223372036854775807, + "ULongValue": 18446744073709551615, "ArrayWithDoubles": [1.1, 2.245, 4.67], "ArrayWithStrings": [ "Key1", "Value 1" ], "ArrayWithInts": [ 1, 2 ], - "ArrayWithBools": [ true, false, true ] + "ArrayWithBools": [ true, false, true ], + "ArrayWithLongs": [ 9223372036854775807, 1234567890123456789 ], + "ArrayWithULongs": [ 18446744073709551615, 1234567890123456789 ] } diff --git a/ConfigGenerator.Tests/TestFiles/expected.cs b/ConfigGenerator.Tests/TestFiles/expected.cs index 4c5b641..2bb2ccc 100644 --- a/ConfigGenerator.Tests/TestFiles/expected.cs +++ b/ConfigGenerator.Tests/TestFiles/expected.cs @@ -1,5 +1,4 @@ - -using System; +using System; using System.Collections.Generic; namespace ApplicationConfig @@ -11,10 +10,14 @@ public class MyAppConfig public bool DuplicateEntryOnlyShowsOnce { get; set; } public int IntValue { get; set; } public double DoubleValue { get; set; } + public long LongValue { get; set; } + public ulong ULongValue { get; set; } public IEnumerable ArrayWithDoubles { get; set; } public IEnumerable ArrayWithStrings { get; set; } public IEnumerable ArrayWithInts { get; set; } public IEnumerable ArrayWithBools { get; set; } + public IEnumerable ArrayWithLongs { get; set; } + public IEnumerable ArrayWithULongs { get; set; } public bool ShowDeveloperWarnings { get; set; } public Logging Logging { get; set; } } diff --git a/src/GenerateConfigClasses.cs b/src/GenerateConfigClasses.cs index dd63806..2f2574f 100644 --- a/src/GenerateConfigClasses.cs +++ b/src/GenerateConfigClasses.cs @@ -135,11 +135,20 @@ private static string GetPropertyTypeNameBasedOnValue(JsonElement value) { return value.ValueKind switch { - JsonValueKind.Number => value.TryGetInt32(out _) ? "int" : "double", + JsonValueKind.Number => DetermineNumericType(value), JsonValueKind.True or JsonValueKind.False => "bool", _ => "string", }; } + + private static string DetermineNumericType(JsonElement value) + { + if (value.TryGetInt32(out _)) return "int"; + if (value.TryGetInt64(out _)) return "long"; + if (value.TryGetUInt64(out _)) return "ulong"; + + return "double"; + } private static string NormalizePropertyName(string originalName) { @@ -218,4 +227,4 @@ private static void MergeDictionaries(Dictionary dictionary1, Di } } } -} +} \ No newline at end of file