diff --git a/Models/Binder/AppSettings.cs b/Models/Binder/AppSettings.cs index e45f245..8cae893 100644 --- a/Models/Binder/AppSettings.cs +++ b/Models/Binder/AppSettings.cs @@ -90,26 +90,23 @@ public class AppSettings Models.AppSettings? results; string? json; if (appSettings is null || appSettings.ConfigurationFileName is null) - json = null; + throw new NotSupportedException($"{nameof(appSettings.ConfigurationFileName)} must be set!"); + string jsonFile = Path.Combine(AppContext.BaseDirectory, appSettings.ConfigurationFileName); + if (File.Exists(jsonFile)) + json = File.ReadAllText(jsonFile); else { - string jsonFile = Path.Combine(AppContext.BaseDirectory, appSettings.ConfigurationFileName); - if (File.Exists(jsonFile)) - json = File.ReadAllText(jsonFile); - else - { - json = null; - string applicationData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); - List collection = [applicationData]; - if (appSettings?.ConfigurationDirectoryNames is not null) - collection.AddRange(appSettings.ConfigurationDirectoryNames); - if (appSettings?.ConfigurationFileName is not null) - collection.Add(appSettings.ConfigurationFileName); - jsonFile = Path.Combine(collection.ToArray()); - } - if (string.IsNullOrEmpty(json) && File.Exists(jsonFile)) - json = File.ReadAllText(jsonFile); + json = null; + string applicationData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); + List collection = [applicationData]; + if (appSettings?.ConfigurationDirectoryNames is not null) + collection.AddRange(appSettings.ConfigurationDirectoryNames); + if (appSettings?.ConfigurationFileName is not null) + collection.Add(appSettings.ConfigurationFileName); + jsonFile = Path.Combine(collection.ToArray()); } + if (string.IsNullOrEmpty(json) && File.Exists(jsonFile)) + json = File.ReadAllText(jsonFile); results = (string.IsNullOrEmpty(json) ? null : results = JsonSerializer.Deserialize(json, AppSettingsSourceGenerationContext.Default.AppSettings)) ?? throw new NullReferenceException(nameof(Models.AppSettings)); results = Get(appSettings,