添加在C#应用程序自定义配置文件 [英] Adding a Custom Configuration file in C# application
问题描述
是否有可能创建一个自定义配置文件(比其他的app.config)
可以通过类System.Configuration命名空间中进行处理?
我见过一吨的谈的自定义栏目(的
app.config文件中)的文章,但我想提出一个全新的配置文件。
有没有涵盖这个主题?
感谢
任何体面的文件< DIV CLASS =h2_lin>解决方案
您没有说明你想要通过让一个单独的文件来实现,但也有几个不同的事情可以做。
如果你想模块化你的配置,你可以打破某些配置节到单独的文件,使用的 configSource
属性:
//指出包含是connectionStrings配置部分
将一个文件,是connectionStrings configSource =connections.config>< /&是connectionStrings GT;
您还可以打开通过调用的 ConfigurationManager.OpenExeConfiguration
。
Is it possible to create a custom configuration file (other than app.config) that can be processed by classes in the System.Configuration namespace?
I have seen a ton of articles that talk about custom sections (inside the app.config file) but I would like to make an entirely new config file.
Is there any decent documentation that covers this topic?
thanks
You do not state what you want to achieve by having a separate file, but there are a couple of different things you can do.
If you want to "modularize" you configuration, you can break out certain config sections to separate files, using the configSource
attribute:
// point out a file containing the connectionStrings config section
<connectionStrings configSource="connections.config"></connectionStrings>
You can also open a specific configuration file by calling ConfigurationManager.OpenExeConfiguration
.
这篇关于添加在C#应用程序自定义配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!