Code required to use foreach on my own custom appSettings

Posted by jamauss on Stack Overflow See other posts from Stack Overflow or by jamauss
Published on 2010-04-02T18:38:14Z Indexed on 2010/04/02 18:43 UTC
Read the original article Hit count: 523

I've searched the site and haven't found exactly what I'm looking for. Close, but no cigar.

Basically I want to have a config section like this:

    <configSections>
        <section name="PhoneNotificationsSection" type="Alerts.PhoneAlertConfigSection,Alerts,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null"/>    
    </configSections>
    <PhoneNotificationsSection>
        <phones>
            <add phone="MyMobile" value="[email protected]" />
            <add phone="OtherMobile" value="[email protected]" />
        </phones>
    </PhoneNotificationsSection>

Then I'd like to, in my appSettings consuming code, be able to write something like this (pseudo code):

foreach (phone p in phones)
{
   //'phone' attribute is just helpful/descriptive
   DoSomething(p.value);
}

I've done enough research to know I probably need a few of my own classes that implement and/or inherit from certain Configuration classes to make the above code possible. I just haven't found anything that clearly demonstrates this scenario and how to code for it - and when I try to learn the whole .NET configuration world my brain starts to hurt. Anyone have some code like what I'm looking for that they can share?

© Stack Overflow or respective owner

Related posts about appsettings

Related posts about configuration