How to read this custom configuration from App.config?
<root name="myRoot" type="rootType">
<element name="myName" type="myType" />
<element name="hisName" type="hisType" />
<element name="yourName" type="yourType" />
</root>
Rather than this:
<root name="myRoot" type="rootType">
<elements>
<element name="myName" type="myType" />
<element name="hisName" type="hisType" />
<element name="yourName" type="yourType" />
</elements>
</root>
To enable your collection elements to sit directly within the parent element (and not a child collection element), you need to redefine your
ConfigurationProperty. E.g., let’s say I have a collection element such as:And a collection such as:
I need to define the parent section/element as:
Notice the
[ConfigurationProperty("", IsDefaultCollection = true)]attribute. Giving it an empty name, and the setting it as the default collection allows me to define my config like:Instead of: