繁体   English   中英

我可以使用ConfigurationManager修改自定义配置部分吗?

[英]Can I modify a custom configuration section using ConfigurationManager?

我有一个形式的App.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <section name="Custom.Config" type="System.Configuration.DictionarySectionHandler, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    </configSections>

    <kCura.Config configSource="Custom.config" />
</configuration>

使用表单的自定义配置文件Custom.config

<?xml version="1.0" encoding="utf-8"?>
<Custom.Config>
    <add key="foo" value="bar" />
</Custom.Config>

我继承了此代码,并且没有与此Custom.Config节关联的现有ConfigurationSectionConfigurationSectionHandler

我可以用以下方法访问foo的值

 DirectCast(System.Configuration.ConfigurationManager.GetSection("Custom.Config"), System.Collections.IDictionary)

但是现在我想以编程方式(出于测试目的) 更新此值。 这可能吗?

我阅读了以下内容,但仍然感到困惑; 它们似乎暗示此命名空间仅用于读取值,而不是完整的CRUD:

您必须使用XDocument修改磁盘上的Custom.config文件,然后需要在ConfigurationManager上调用RefreshSection

然后,这将刷新命名的节,以便下次检索它时将从磁盘重新读取它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM