【发布时间】:2013-04-23 16:30:20
【问题描述】:
我在 machine.config 中持有一个自定义配置部分,其结构如下:
<CustomSettings>
<add key="testkey" local="localkey1" dev="devkey" prod="prodkey"/>
</CustomSettings>
现在,我希望能够通过将覆盖存储在 app.config 中来覆盖相同的键设置,如下所示:
<CustomSettings>
<add key="testkey" dev="devkey1" prod="prodkey1"/>
</CustomSettings>
所以当我在代码中阅读它时,我会得到 - dev="devkey1", prod="prodkey1", local="localkey1"
问题是当我像这样阅读我的自定义配置部分时:
CustomConfigurationSection section = ConfigurationManager.GetSection("CustomSettings") as CustomConfigurationSection;
我收到一条错误消息,指出已添加密钥:
“已添加条目‘testkey’。”
我修改了 ConfigElementCollection.Add 函数来检查相同的键是否已经存在但它不起作用。
有什么想法吗?
【问题讨论】:
标签: c# configurationmanager configurationelement configsection