Refactor
This commit is contained in:
		| @ -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<string> 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<string> 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, | ||||
|  | ||||
		Reference in New Issue
	
	Block a user