I need custom configuration in following way
<root>
<group>
<groupitem>
<property1/>
<property2/>
<property3/>
<property4/>
</groupitem>
<group>
</root>
I am not finding any example of how to do that.
Following comes very close,
Nested Configuration Section app.config
but still I am stuck on defining class corresponding to groupitem. If I change property1
, property2
from element to attribute, that is easy to define.
But that will create problem if these properties have nested properties.
Question is, How to define the nested hierarchy in the way defined above?
The configuration section is the top-level element of some configuration model. For example, your product name would be the configuration section.
Any other nested element is a ConfigurationElement
or ConfigurationElementCollection
.
Actually you can also create custom section groups deriving ConfigurationSectionGroup
.
Taking your configuration:
<root> <!-- This is a ConfigurationSection -->
<group><!-- This is a ConfigurationElement -->
<groupitem> <-- This could be a ConfigurationElement having child items of type ConfigurationElement or a ConfigurationElementCollection -->
<property1/> <!-- This is a ConfigurationElement -->
<property2/> <!-- This is a ConfigurationElement -->
<property3/> <!-- This is a ConfigurationElement -->
<property4/> <!-- This is a ConfigurationElement -->
</groupitem>
<group>
If you really want to know how to work with .NET configuration model, take a look at these articles:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With