4
У меня есть App.config с пользовательскими конфигурациямиПользовательские конфигурации с C#
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="wsa" type="WSASRT.SRT.WSA.WsaConfig" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<wsa>
<src E="[email protected]" CN="AnotherFoo" OU="AnotherBar" />
<!-- More elements -->
</wsa>
</configuration>
И следующее отображение класса
namespace WSASRT.SRT.WSA
{
class WsaConfig : ConfigurationSection
{
[ConfigurationProperty("src")]
public SrcElement Src { get { return (SrcElement)this["src"]; } }
}
public class SrcElement : ConfigurationElement
{
[ConfigurationProperty("E")]
public string E { get { return (String)this["E"]; } }
[ConfigurationProperty("CN")]
public string CN { get { return (String)this["CN"]; } }
}
}
И мой Program.cs выглядит как:
class Program
{
static void Main(string[] args)
{
WsaConfig config = new WsaConfig();
Console.WriteLine(config.Src.CN);
Console.ReadLine();
}
}
Когда я запускаю его, я получаю пустую строку, но мне нужно получить «AnotherFoo». Что я делаю не так?