I want to create a config list object from a my app.config file. This is what the config file looks like:
<configuration>
<appSettings>
<add key="SomeKey" value="some key's value"/>
<add key="AnotherKey" value="another key's value"/>
</appSettings>
<ExtraSettings>
<Url = "Some url here" Timeout="" Active="true" Source="some other value">
<Url = "Some url here" Timeout="" Active="true" Source="some other value">
</ExtraSettings>
</configuration>
App settings I can get using the regular .Net ConfigurationManager class. The problem is I am not able to create a list of my Settings class from the ExtraSettings section as above to map to my ExtraSettings class as below
public class ExtraSettings
{
public string SomeKey { get; set; }
public string AnotherKey{ get; set; }
public List<Settings> SettingsList { get; set; }
}
public class Settings
{
[ConfigurationProperty("Url")]
public string Url { get; set; }
[ConfigurationProperty("Timeout")]
public string Timeout { get; set; }
[ConfigurationProperty("Source")]
public string Source { get; set; }
[ConfigurationProperty("Active")]
public string Active { get; set; }
}
I am stuck at this section in my code.
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
List<Settings> settingsList = config.GetSection("ExtraSettings") ;
Am I in the right direction? What changes do I need to make?