[英]Can I modify a custom configuration section using ConfigurationManager?
I have an App.config
of the form 我有一个形式的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>
With a custom configuration file Custom.config
of the form 使用表单的自定义配置文件Custom.config
<?xml version="1.0" encoding="utf-8"?>
<Custom.Config>
<add key="foo" value="bar" />
</Custom.Config>
I've inherited this code, and there is no existing ConfigurationSection
or ConfigurationSectionHandler
associated with this Custom.Config
section. 我继承了此代码,并且没有与此Custom.Config
节关联的现有ConfigurationSection
或ConfigurationSectionHandler
。
I can access the value of foo
just fine with 我可以用以下方法访问foo
的值
DirectCast(System.Configuration.ConfigurationManager.GetSection("Custom.Config"), System.Collections.IDictionary)
But now I would like to update this value, programatically (for testing purposes). 但是现在我想以编程方式(出于测试目的) 更新此值。 Is this possible? 这可能吗?
I've read the following, and I'm still stumped; 我阅读了以下内容,但仍然感到困惑; they seem to imply that this namespace is only for reading values, not full CRUD: 它们似乎暗示此命名空间仅用于读取值,而不是完整的CRUD:
You'll have to modify the Custom.config
file on disk by using XDocument then you'll need to call RefreshSection
on the ConfigurationManager 您必须使用XDocument修改磁盘上的Custom.config
文件,然后需要在ConfigurationManager上调用RefreshSection
This will then refresh the named section so the next time that it is retrieved it will be re-read from disk. 然后,这将刷新命名的节,以便下次检索它时将从磁盘重新读取它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.