简体   繁体   English

在运行时覆盖/替换app.config中的ConfigurationElements

[英]overriding/replacing ConfigurationElements in app.config in runtime

I have two ConfigurationElement objects (one of which is in the running application's app.config) and I need to replace that one with the other. 我有两个ConfigurationElement对象(其中一个在运行的应用程序的app.config中),我需要将其替换为另一个。 I also have the ConfigurationElementCollection that the first element belongs to. 我还有第一个元素所属的ConfigurationElementCollection。 It looks like the Add and Remove methods are protected internal. 看起来Add和Remove方法在内部受到保护。 Is it not intended for me to be able to update the ConfigurationElementCollection object in runtime? 我不打算在运行时更新ConfigurationElementCollection对象吗? If so, what are the alternatives? 如果是这样,有哪些替代方案?

Thanks. 谢谢。

ConfigurationElementCollection is an abstract class, so the concrete collection class might expose methods to add and remove. ConfigurationElementCollection是一个抽象类,因此具体集合类可能会公开要添加和删除的方法。

However, when retrieved using the ConfigurationManager.GetSection method configuration is read only so even if the methods were accessible they would not work: 但是,使用ConfigurationManager.GetSection方法检索时,配置是只读的,因此即使方法可访问,它们也不起作用:

The GetSection method accesses run-time configuration information that it cannot change. GetSection方法访问无法更改的运行时配置信息。 To change the configuration, you use the GetSection method on the configuration file that you obtain by using one of the following Open methods: 若要更改配置,请在使用以下Open方法之一获取的配置文件上使用GetSection方法:

What do you need to accomplish, and who is consuming that configuration? 您需要完成什么,以及谁正在使用该配置? You might be able to change its behavior at a higher level rather than swapping the configuration information. 您可能能够在更高级别更改其行为,而不是交换配置信息。

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

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