単純なものが欠けているだけだといいのですが。exe.configファイルのセクションに対して読み取り/書き込みを行う必要があります。私は私のコードにこれを持っています:
var appConfiguration = ConfigurationManager.OpenExeConfiguration("Mytest.Console.exe");
var fileEnvironment = appConfiguration.GetSection("fileEnvironment");
これは私のapp.configです:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="fileEnvironment" type="System.Configuration.DictionarySectionHandler"/>
</configSections>
<fileEnvironment>
<add key="TestEntry1" value="A nice value"/>
<add key="TestEntry2" value="Another value"/>
</fileEnvironment>
</configuration>
appConfiguration変数は{System.Configuration.Configuration}として返され、「HasFile」プロパティがtrueに設定されます。
変数をキャストしないと、「fileEnvironment」はとして返されSystem.Configuration.DefaultSection
ます。メソッドに追加するIDictionary<string, string>
と、GetSection
fileEnvironmentはnullになります。
何か案は?