I have (hopefully) setup ConfigurationElementCollection of my own design with emails as keys. Now what? Hard to find actually on the web. How do I:
iterate through it?
See if a specific element exists?
get a specific element?
...given:
YourConfigElement config =
ConfigurationManager.GetSection("YourSectionName") as YourConfigElement;
Partial answer
1.
foreach (X x in config.XCollection)
<code here>
2 . replace "code here" with
{
if (x.Y == needle)
{
hasIndeed = true;
break;
}
}
3 . replace "code here" with
{ if (x.Y == needle)
cameUpWith = x;
break;
}
Tiny odor.
What you want is your own generic
ConfigurationElementCollection
base class which implementsIList<T>
. You can then inherit from this for all your configuration collections and cut down on the amount of work you need to do when creating configuration collections.With a little bit more work you can have a dictionary collection as well.