App Config文件 - 确保自定义配置结构

时间:2012-11-15 14:37:44

标签: c# .net app-config

我有一个从app.config中的自定义部分读取的库

是否有正确的方法可以确保在项目中使用此库时,如果未提供该库,则会创建其自定义部分的“骨架”?

我想确保无论什么时候使用此版本,他们都能够理解他们有权访问配置而无需查看库内部。

编辑:为了更具体,这里有一个示例应用程序配置,并对我正在尝试做的事情有一些解释

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="CustomSection" type="Test.CustomSection, CustomSection"/>
    </configSections>
    <CustomSection SettingOne="My Setting"/>
</configuration>

这是我将创建的一个部分的示例,知道SettingOne是一个有效的设置,并且知道CustomSection和所有这些。我想做的是拥有我的CustomSection.dll文件,当在项目中包含和使用时,更新配置文件以确保CustomSection可用于某些默认设置。

我想成为这样的结果:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section .... >
        <section .... >
        <!-- Custom Section below added -->
        <section name="CustomSection" type="Test.CustomSection, CustomSection"/>
    </configSections>
    <!-- Settings below also added -->
    <CustomSection SettingOne="DEFAULT"/>
</configuration>

0 个答案:

没有答案
相关问题