我想从app.config文件创建配置列表对象。 这就是配置文件的样子:
<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>
应用程序设置我可以使用常规的.Net ConfigurationManager类。问题是我无法从ExtraSettings部分创建我的Settings类列表,如上所示,以映射到我的ExtraSettings类,如下所示
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; }
}
我在我的代码中被困在这一部分。
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
List<Settings> settingsList = config.GetSection("ExtraSettings") ;
我是朝着正确的方向吗?我需要做出哪些改变?