Refactor
This commit is contained in:
		| @ -90,26 +90,23 @@ public class AppSettings | |||||||
|         Models.AppSettings? results; |         Models.AppSettings? results; | ||||||
|         string? json; |         string? json; | ||||||
|         if (appSettings is null || appSettings.ConfigurationFileName is null) |         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 |         else | ||||||
|         { |         { | ||||||
|             string jsonFile = Path.Combine(AppContext.BaseDirectory, appSettings.ConfigurationFileName); |             json = null; | ||||||
|             if (File.Exists(jsonFile)) |             string applicationData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); | ||||||
|                 json = File.ReadAllText(jsonFile); |             List<string> collection = [applicationData]; | ||||||
|             else |             if (appSettings?.ConfigurationDirectoryNames is not null) | ||||||
|             { |                 collection.AddRange(appSettings.ConfigurationDirectoryNames); | ||||||
|                 json = null; |             if (appSettings?.ConfigurationFileName is not null) | ||||||
|                 string applicationData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); |                 collection.Add(appSettings.ConfigurationFileName); | ||||||
|                 List<string> collection = [applicationData]; |             jsonFile = Path.Combine(collection.ToArray()); | ||||||
|                 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); |  | ||||||
|         } |         } | ||||||
|  |         if (string.IsNullOrEmpty(json) && File.Exists(jsonFile)) | ||||||
|  |             json = File.ReadAllText(jsonFile); | ||||||
|         results = (string.IsNullOrEmpty(json) ? null : results = JsonSerializer.Deserialize(json, AppSettingsSourceGenerationContext.Default.AppSettings)) ?? |         results = (string.IsNullOrEmpty(json) ? null : results = JsonSerializer.Deserialize(json, AppSettingsSourceGenerationContext.Default.AppSettings)) ?? | ||||||
|             throw new NullReferenceException(nameof(Models.AppSettings)); |             throw new NullReferenceException(nameof(Models.AppSettings)); | ||||||
|         results = Get(appSettings, |         results = Get(appSettings, | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user