Home All Groups Group Topic Archive Search About

Question on ConfigurationElementCollection design

Author
10 Jul 2006 3:09 PM
mbu27
A while back, a question was posted on ConfigurationElementCollection design as follows:

I have 2 questions on using element collections when building a custom
section handler.  I'm using the "declarative" model and I can post the code
if necessary.  Basically I'm following the example described here:

http://msdn2.microsoft.com/en-us/library/system.configuration.configurationcollectionattribute.aspx

My code works and the XML in app.config for my custom section looks like this:

MySection name="x"
    Stores
        add name="store1"
        add name="store2"
    Stores
MySection

But I have 2 sort of "cosmetic" questions about changing the XML:

1.  If I change "add..." to "Store..." it gives a runtime error that it
doesn't recognize the Store element.  But I don't see anywhere in my code
where I tell the system to look for the "add" element, so why doesn't it
complain about that?  I'd prefer the "Store..." syntax but can't see how to
override or redefine this behavior.

2. In some cases it might also be nicer to skip the outermost "Stores"
element and just have this:

MySection name="x"
     Store name="store1"
     Store name="store2"
MySection

But I don't see how to arrange for this in the declarations of a
ConfigurationElementCollection.  It seems to require the outermost element to
key on its name.  What I want is sort of an "unnamed" collection of Stores.

The first part of the question was answered by using the ConfigurationCollection attribute.

Was there ever get a solution to the "unnamed" part (part 2) of the question? I'd like to also add a section collection to my config section and adding a name is redundant. ie., the "Stores" element in you sample. Can an "unnamed" section be added to a ConfigurationElementCollection?

AddThis Social Bookmark Button