App.Config中的自定义部分:如何在C#中实现这个结构?

时间:2015-01-29 14:20:06

标签: c# xml app-config custom-sections

我为App.Config文件创建了自定义配置部分,现在它看起来像这样:

<mySection>
  <myCollection>
    <element name="1" />
    <element name="2" />
  </myCollection>
</mySection>

正如命名所示,我的类继承自ConfigurationSectionMySection),ConfigurationElementCollectionMyCollection AddItemName="element",其属性设为MySection 1}})和ConfigurationElement。但我想知道如何实现类似于以下的结构:

<mySection>
  <myElements>
    <element name="1" />
    <element name="2" />
    <additionalInfo>"..."</additionalInfo>
  </myElements>
  <someOtherSetting option="blub" />
</mySection>

我仍可以ConfigurationElementCollection使用MyElements,还是必须使用其他内容,因为element标记(由AddItemName="element"指定{ {1}}类),还有另一个?如果没有,这里使用的课程是什么?

我觉得标签之间的某些内容必须与某个MySection类的属性相对应,以便它等同于以下内容?

AdditionalInfo

至于<additionalInfo content="..." /> 我想我可以添加另一个与someOtherSetting相对应的属性,但我还没有进行测试。

0 个答案:

没有答案