我正在嘗試在我的C#.NET控制檯應用程序的app.config文件中創建自定義配置節。這是一些細節存儲有關的一些服務器,例如:app.config中的多個相同的自定義配置
<configSections>
<sectionGroup name="serverGroup">
<section name="server" type="RPInstaller.ServerConfig" allowLocation="true" allowDefinition="Everywhere"/>
</sectionGroup>
</configSections>
<serverGroup>
<server>
<name>rmso2srvm</name>
<isBatchServer>false</isBatchServer>
</server>
<server>
<name>rmsb2srvm</name>
<isBatchServer>true</isBatchServer>
</server>
</serverGroup>
我對服務器的部分定義,像這樣一類:
namespace RPInstaller
{
public class ServerConfig : ConfigurationSection
{
[ConfigurationProperty("name", IsRequired=true)]
public string Name {...}
[ConfigurationProperty("isBatchServer", IsRequired = true)]
public bool IsBatchServer {...}
}
}
當我現在嘗試加載服務器部分我得到一個例外:「節只能在每個配置文件中出現一次」。
我怎麼能夠合法地定義我的app.config文件中的多個服務器節?
真正的答案是這個和VMAtm留下的混合物。我發現以下問題的答案中的鏈接非常有用:[Custom Configuration Sections](http://stackoverflow.com/questions/858618/custom-configuration-sections) – 2011-05-25 07:38:03