I'm trying to convert appsettings.json to C# class
I use Microsoft.Extensions.Configuration
to read the configuration from appsettings.json
I write the following code using reflection but I'm looking for a better solution
foreach (var (key, value) in configuration.AsEnumerable())
{
var property = Settings.GetType().GetProperty(key);
if (property == null) continue;
object obj = value;
if (property.PropertyType.FullName == typeof(int).FullName)
obj = int.Parse(value);
if (property.PropertyType.FullName == typeof(long).FullName)
obj = long.Parse(value);
property.SetValue(Settings, obj);
}