24 lines
809 B
C#
24 lines
809 B
C#
using System.Text.Json;
|
|
|
|
namespace APCViewer.Models.Stateless;
|
|
|
|
public abstract class AppSettings
|
|
{
|
|
|
|
public static Models.AppSettings Get(IConfigurationRoot configurationRoot)
|
|
{
|
|
Models.AppSettings? result;
|
|
Models.Binder.AppSettings appSettings = configurationRoot.Get<Models.Binder.AppSettings>();
|
|
string json = JsonSerializer.Serialize(appSettings, new JsonSerializerOptions() { WriteIndented = true });
|
|
result = JsonSerializer.Deserialize<Models.AppSettings>(json);
|
|
if (result is null)
|
|
throw new Exception(json);
|
|
if (string.IsNullOrEmpty(result.Company))
|
|
throw new Exception(json);
|
|
string jsonThis = result.ToString();
|
|
if (jsonThis != json)
|
|
throw new Exception(json);
|
|
return result;
|
|
}
|
|
|
|
} |