-
Notifications
You must be signed in to change notification settings - Fork 0
Examples Basic
#Description
In this section we are going to show the most simple way to read configurations. In the advanced section we will cover more complex scenarios such as specifying extraction strategies or mapping properties to keys where there is a name difference.
#AppSettings
Reading from the AppSettings is already quite easy in .Net however you still need to parse your keys to ensure they exist and to convert them to the appropriate primitive types. ConfigurationAssist helps speed up this process by allowing you to read only parts of your AppSettings into a configuration class and performing the necessary primitive type conversion for you. Below is the most basic scenario for reading AppSettings. Note if you only specify some of the keys, only those keys will be read. This allows you to create settings "groups".
<AppSettings>
<add key="TestValue" value="Value1" />
<add key="DecimalValue" value="1.5" />
<add key="IntegerValue" value="9" />
</AppSettings>Create a simple c# class that has properties names exactly the same as the propertes in AppSettings you want to read (Case Sensitive).
public class MySettings
{
public string TestValue { get; set; }
public decimal DecimalValue { get; set; }
public int IntegerValue { get; set; }
}Finally to read it, simply create a new instance of ConfigurationAssist, then extract your object.
var config = new ConfigurationAssist();
var settings = config.ExtractSettings<MySettings>();