G
Guest
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" addr="x" />
<add name="store2" addr="y" />
</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" addr="x" />
<Store name="store2" addr="y" />
</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.
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" addr="x" />
<add name="store2" addr="y" />
</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" addr="x" />
<Store name="store2" addr="y" />
</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.