Fixed Warnings

This commit is contained in:
Matthias Heil
2026-04-05 08:00:09 +02:00
parent dfb879bfb3
commit 511a5f9f51
21 changed files with 104 additions and 115 deletions
+16 -22
View File
@@ -4,42 +4,36 @@ namespace Common.Core;
public class AppSettings<TOption>
{
#region Constructors
#region Constructors
public AppSettings(IConfigurationSection configSection, string? key = null)
{
_configSection = configSection;
ConfigSection = configSection;
// ReSharper disable once VirtualMemberCallInConstructor
GetValue(key);
}
#endregion
#region Fields
protected static AppSettings<TOption>? _appSetting;
// ReSharper disable once StaticMemberInGenericType
protected static IConfigurationSection? _configSection;
#endregion
#region Properties
public TOption? Value { get; set; }
protected static AppSettings<TOption>? AppSetting { get; private set; }
// ReSharper disable once StaticMemberInGenericType
protected static IConfigurationSection? ConfigSection { get; private set; }
public TOption? Value { get; set; }
#endregion
#region Methods
#region Methods
#pragma warning disable CA1000 // Do not declare static members on generic types
public static TOption? Current(string section, string? key = null)
{
_appSetting = GetCurrentSettings(section, key);
return _appSetting.Value;
AppSetting = GetCurrentSettings(section, key);
return AppSetting.Value;
}
public static AppSettings<TOption> GetCurrentSettings(string section, string? key = null)
#pragma warning restore CA1000 // Do not declare static members on generic types
{
string env = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") ?? "Production";
@@ -65,7 +59,7 @@ public class AppSettings<TOption>
{
// no key, so must be a class/strut object
Value = Activator.CreateInstance<TOption>();
_configSection!.Bind(Value);
ConfigSection!.Bind(Value);
return;
}
@@ -77,10 +71,10 @@ public class AppSettings<TOption>
optionType == typeof(decimal) ||
optionType == typeof(float) ||
optionType == typeof(double))
&& _configSection != null)
&& ConfigSection != null)
{
// we must be retrieving a value
Value = _configSection.GetValue<TOption>(key);
Value = ConfigSection.GetValue<TOption>(key);
return;
}