1

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

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

我想确保无论何时,无论谁使用这个 get,他们都能够理解他们有权配置的内容,而无需查看库内部。

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

<?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>
4

0 回答 0