【发布时间】:2011-10-18 16:05:09
【问题描述】:
我想要的 app.config 是这样的:
<configSections>
<sectionGroup name="QA_Environment">
<section name="databases" type="System.Configuration.NameValueSectionHandler"/>
<section name="storageSystems" type="System.Configuration.NameValueSectionHandler"/>
</sectionGroup>
<sectionGroup name="Production_Environment">
<section name="databases" type="System.Configuration.NameValueSectionHandler"/>
<section name="storageSystems" type="System.Configuration.NameValueSectionHandler"/>
</sectionGroup>
</configSections>
...然后我在其下方找到了实际的组和部分。但我会对任何有效或更好的建议感到满意。我现在降低了我的愿望:
<configSections>
<sectionGroup name="QA_Environment">
<section name="appSettings" type="System.Configuration.NameValueSectionHandler"/>
</sectionGroup>
<sectionGroup name="Production_Environment">
<section name="appSettings" type="System.Configuration.NameValueSectionHandler"/>
</sectionGroup>
</configSections>
我想这很好...我想知道的主要问题是我是否可以将这些部分之一替换为根级别的 appSettings...无需遍历它们并以编程方式添加或创建配置并保存它.我只是希望用户能够选择一个环境,选择事件会改变 appSettings...
我面临的一个限制是我引用的数据层需要保持原样......所以我基本上需要让我的 app.config 可以完全像现在一样访问这些其他项目...即 ConfigurationManager.AppSettings[afdasdf]
如果这需要任何澄清,请告诉我...谢谢
【问题讨论】:
标签: c# app-config appsettings configurationmanager custom-sections