移动自定义配置组到一个单独的文件 [英] Moving a custom configuration group to a separate file

查看:163
本文介绍了移动自定义配置组到一个单独的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近写了一个相当大的自定义配置组。我很好奇,如果有可能该结构通过以下移动到一个单独的文件:

I've recently wrote a rather large custom configuration group. I'm curious if it is possible to move this configuration to a separate file via the following:

<configuration>
    <configSections>
    	<sectionGroup name="MyCustomGroup">
    		<section name="MyCustomSection"/>
    	</sectionGroup>
    </configSections>
    <MyCustomGroup file="alt.config" />
</configuration>

这是类似于您可以与的appSettings文件属性做一些事情。我知道有是最有可能需要建立一个ConfigurationPropertyAttribute为我的自定义节处理程序,但我已经在寻找这方面的例子或方向是不成功的。

This is something similar to what you can do with the file attribute for appSettings. I realize there is most likely a need to create a ConfigurationPropertyAttribute for my custom section handler, however I've been unsuccessful in finding any example or direction in this regard.

推荐答案

据我所知,你的不能的外部化整个SectionGroup(即 MyCustomGroup )使用 configSource 属性,但你必须处理这对科级(即 MyCustomSection

As far as I know, you cannot externalize an entire SectionGroup (i.e. MyCustomGroup) using the configSource attribute, but you have to handle this on the Section level (i.e. MyCustomSection)

<configuration>
    <configSections>
        <sectionGroup name="MyCustomGroup">
                <section name="MyCustomSection"/>
        </sectionGroup>
    </configSections>
    <MyCustomGroup>    
       <MyCustomSection configSource="externalfile.config" />
    </MyCustomGroup>
</configuration>

外部文件 externalfile.config 将包含您的实际的配置设置,直接用自己的自定义栏目标签开始(没有前导&LT ;? ?XML ....&GT; &lt;结构&GT; 或需要什么):

The external file externalfile.config would then contain your actual config settings, starting directly with your own custom section tag (no leading <?xml....?> or <configuration> or anything needed):

<MyCustomSection>
    ... your settings here......
</MyCustomSection>

马克·

这篇关于移动自定义配置组到一个单独的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆