簡體   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