且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将自定义部分写入 app.config

更新时间:2022-06-16 21:58:53

首先覆盖 CustomConfigSection 中的 IsReadyOnly() 以返回 false.

First override IsReadyOnly() in your CustomConfigSection to return false.

一旦你这样做了,你应该能够做这样的事情(这是针对 ASP.NET,但它可能是可转移的):

Once you've done that you should be able to do something like this (this is for ASP.NET, but it might be transferably):

System.Configuration.Configuration configFile = WebConfigurationManager.OpenWebConfiguration("~");
CustomConfigSection config = (CustomConfigSection)configFile.GetSection("Custom");
config.Tweak = 1;
config.Change = "foo";
configFile.Save();

试试看.