NuGet Gallery Feed for Sayer.WebConfigClass for retrieving settings from web.config, optionally related to a type. A separate project exists for app.config files.
Below is an example for a config file, which assumes the existence of class Base, as well as classes Buggy and Stable, which inherit from Base (all in the same assembly). In the example, type Buggy has log level Debug, Stable has level Error, and all other derivatives of Base have level Warn. Classes not inheriting from Base have level Info. All types have Timestamp set to true in the example.
<configuration>
<configSections>
<section name = "logSection" type="Sayer.Config.ConfigSection"/>
</configSections>
<logSection>
<field name="LogLevel" value="Info"/>
<field name="Base.LogLevel" value="Warn"/>
<field name="Base.Buggy.LogLevel" value="Debug"/>
<field name="Base.Stable.LogLevel" value="Error"/>
<field name="Timestamp" value="true"/>
</logSection>
<configuration/>
The following statement, given the .config settings below, would return the value Debug:
WebAppSettings.Get<LogLevel>("logSection", typeof(Buggy), "LogLevel");
The following statement would return the value Info:
WebAppSettings.Get<LogLevel>("logSection", "LogLevel");
And the following statement would return true:
WebAppSettings.Get<bool>("logSection", typeof(MyClass), "Timestamp")https://www.nuget.org/packages/Sayer.WebConfig/2021-05-06T14:42:39Zhttps://www.nuget.org/packages/Sayer.WebConfig/1.0.0Sayer.WebConfig 1.0.02021-05-06T14:41:05Z2021-05-06T14:42:39Zefielekehttps://www.nuget.org/profiles/efielekeClass for retrieving settings from web.config, optionally related to a type. A separate project exists for app.config files.
Below is an example for a config file, which assumes the existence of class Base, as well as classes Buggy and Stable, which inherit from Base (all in the same assembly). In the example, type Buggy has log level Debug, Stable has level Error, and all other derivatives of Base have level Warn. Classes not inheriting from Base have level Info. All types have Timestamp set to true in the example.
<configuration>
<configSections>
<section name = "logSection" type="Sayer.Config.ConfigSection"/>
</configSections>
<logSection>
<field name="LogLevel" value="Info"/>
<field name="Base.LogLevel" value="Warn"/>
<field name="Base.Buggy.LogLevel" value="Debug"/>
<field name="Base.Stable.LogLevel" value="Error"/>
<field name="Timestamp" value="true"/>
</logSection>
<configuration/>
The following statement, given the .config settings below, would return the value Debug:
WebAppSettings.Get<LogLevel>("logSection", typeof(Buggy), "LogLevel");
The following statement would return the value Info:
WebAppSettings.Get<LogLevel>("logSection", "LogLevel");
And the following statement would return true:
WebAppSettings.Get<bool>("logSection", typeof(MyClass), "Timestamp")