2

ConfigurationManager.OpenMappedExeConfigurationを使用して、リモートWebサービスのweb.configファイルを読み取って変更しています。これはほとんどの場合うまく機能します。設定ファイルは、を使用してユニティ設定セクションを分割します

    <unity configSource="Unity1.config"/>

Unity2.configを指すようにこれを変更するにはどうすればよいですか?私は試した

    Config.Sections["unity"].SectionInformation.ConfigSource = "Unity2.config"

これにより、web.configファイルが更新されます。ただし、Unity2.configがUnity1.configの内容で上書きされることもありますが、これは私が望んでいることではありません。

また、この方法で開いた構成オブジェクトを更新する方法はありますか?

4

1 に答える 1

0
var config = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
var section = config.GetSection(UnityConfigurationSection.SectionName) as UnityConfigurationSection;
if (section == null)
{
     section = new UnityConfigurationSection();
     config.Sections.Add(UnityConfigurationSection.SectionName, section);
}

section.SectionInformation.ConfigSource = "unity.config";
config.Save(ConfigurationSaveMode.Full);

正常に動作します

于 2016-12-30T13:33:59.493 に答える