From e8a7373da52ae23344a5f3cc9ff67b2d3beb3e66 Mon Sep 17 00:00:00 2001 From: Pattrigue Date: Sat, 9 Sep 2023 11:23:44 +0200 Subject: [PATCH 1/3] Add support for 64-bit numerical data types --- ConfigGenerator.Tests/TestFiles/appsettings.json | 6 +++++- ConfigGenerator.Tests/TestFiles/expected.cs | 7 +++++-- src/GenerateConfigClasses.cs | 13 +++++++++++-- 3 files changed, 21 insertions(+), 5 deletions(-) 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 From 95b9f43d8a59cce6c5ecac93a92215ed394725ee Mon Sep 17 00:00:00 2001 From: Pattrigue Date: Sat, 9 Sep 2023 12:05:11 +0200 Subject: [PATCH 2/3] Update ConfigGenerator.csproj --- src/ConfigGenerator.csproj | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ConfigGenerator.csproj b/src/ConfigGenerator.csproj index 3fea994..52236b8 100644 --- a/src/ConfigGenerator.csproj +++ b/src/ConfigGenerator.csproj @@ -10,12 +10,13 @@ - ConfigGenerator + ConfigurationGenerator git - https://github.com/albertromkes/config-poco-generator - Generates POCO classes from your appsettingsfiles - Albert Romkes - 1.0.4 + https://github.com/pattrigue/config-poco-generator + Generates POCO classes from your appsettingsfiles. +Fork of https://github.com/albertromkes/config-poco-generator. + Albert Romkes & Pattrigue + 1.0.5 README.md From f5de1f8c30f095d088506e41ad1cfcb277a2817d Mon Sep 17 00:00:00 2001 From: Pattrigue Date: Sat, 9 Sep 2023 13:12:52 +0200 Subject: [PATCH 3/3] Revert "Update ConfigGenerator.csproj" This reverts commit 95b9f43d8a59cce6c5ecac93a92215ed394725ee. --- src/ConfigGenerator.csproj | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/ConfigGenerator.csproj b/src/ConfigGenerator.csproj index 52236b8..3fea994 100644 --- a/src/ConfigGenerator.csproj +++ b/src/ConfigGenerator.csproj @@ -10,13 +10,12 @@ - ConfigurationGenerator + ConfigGenerator git - https://github.com/pattrigue/config-poco-generator - Generates POCO classes from your appsettingsfiles. -Fork of https://github.com/albertromkes/config-poco-generator. - Albert Romkes & Pattrigue - 1.0.5 + https://github.com/albertromkes/config-poco-generator + Generates POCO classes from your appsettingsfiles + Albert Romkes + 1.0.4 README.md