Custom section in App.Config: How to realize this structure in C#?

93 Views Asked by At

I have created a custom configuration section for my App.Config file, right now it looks like this:

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

As the naming suggests, I have classes inherited from ConfigurationSection (MySection), ConfigurationElementCollection (MyCollection with AddItemName="element" set in the attributes of MySection), and ConfigurationElement. But I wonder how I can realize a structure similar to the following:

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

Can I still use ConfigurationElementCollection for MyElements or do I have to use something else, as there is not just the element tag (specified by AddItemName="element" in the MySection class), but also another one? If not, what is the class to use here?

And I guess having something between the tags has to just correspond to a property of some AdditionalInfo class, so that it'd be equivalent to the following?

<additionalInfo content="..." />

As for someOtherSetting I guess I could just add another property to MySection corresponding to this, but I didn't get to testing that yet.

0

There are 0 best solutions below