将自定义配置组移动到单独的文件中
我最近写了一个相当大的自定义配置组。我很好奇是否可以通过以下方式将此配置移至单独的文件:
<configuration>
<configSections>
<sectionGroup name="MyCustomGroup">
<section name="MyCustomSection"/>
</sectionGroup>
</configSections>
<MyCustomGroup file="alt.config" />
</configuration>
这与您可以使用 appSettings 的文件属性执行的操作类似。我意识到很可能需要为我的自定义部分处理程序创建 ConfigurationPropertyAttribute,但是我没有成功找到这方面的任何示例或方向。
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>
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,您不能使用
configSource
属性外部化整个SectionGroup(即MyCustomGroup
),但是您必须在部分级别(即MyCustomSection
)外部文件
externalfile.config
将包含您的实际配置设置,直接从您自己的自定义部分标记开始(没有前导< ?xml....?>
或
或任何需要的内容):Marc
As far as I know, you cannot externalize an entire SectionGroup (i.e.
MyCustomGroup
) using theconfigSource
attribute, but you have to handle this on the Section level (i.e.MyCustomSection
)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):Marc