How would I need to write my custom ConfigurationSection
so that it is both a section handler and a configuration element collection?
Normally, you have one class that inherits from ConfigurationSection
, which then has a property that is of a type that inherits from ConfigurationElementCollection
, which then returns elements of a collection of a type that inherits from ConfigurationElement
. To configure that, you would then need XML that looks something like this:
<customSection>
<collection>
<element name="A" />
<element name="B" />
<element name="C" />
</collection>
</customSection>
I want to cut out the <collection>
node, and just have:
<customSection>
<element name="A" />
<element name="B" />
<element name="C" />
<customSection>
I assume that the
collection
is a property of your customConfigurationSection
class.You can decorate this property with the following attributes:
A full implementation for your example could look like this:
Now you can access your settings like this:
This will allow the following configuration section: