views:

399

answers:

2

I would like to have a configuration section like the following:

<mycollection>
 <add name="myelement" type="class, assembly" var1="value" var2="value" />
 <add name="myelement2" type="class2, assembly" var1="value" var3="value" var4="value" />
</mycollection>

The idea being that the actual ConfigurationElement created is defined by the type value, and that each element will have its own specific set of attributes.

Another option would be that all the elements are the same, but they load the values from a different configuration section, e.g.:

<mycollection>
 <add name="myelement" configuration="myothersection" />
 <add name="myelement2" configuration="myothersection2" />
</mycollection>

<myothersection type="class, assembly" var1="value" var2="value" />

This seems easier to implement but leads to more verbose configuration file.

Is the first option respecting the .NET configuration pattern, and secondly, is that possible?

A: 

No, is not possible.

Art Wide
It's not possible or you don't know how to? I have the same problem and was wondering about it myself.
guardi
A: 

Yes it is possible! Check out this post for details:

http://code.dblock.org/ShowPost.aspx?Id=34

Along the same lines here a solution that allows you to read extremely flexible xml using IConfigurationSectionHandler: http://alt.pluralsight.com/wiki/default.aspx/Craig/XmlSerializerSectionHandler.html

Mike Glenn
Thanks for this
Lee Atkinson