相关疑难解决方法(0)

在我自己的自定义appSettings上使用foreach所需的代码

我搜索过该网站,并没有找到我正在寻找的确切内容.关闭,但没有雪茄.

基本上我想要一个像这样的配置部分:

    <configSections>
        <section name="PhoneNotificationsSection" type="Alerts.PhoneAlertConfigSection,Alerts,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null"/>    
    </configSections>
    <PhoneNotificationsSection>
        <phones>
            <add phone="MyMobile" value="1234567890@vtext.com" />
            <add phone="OtherMobile" value="1234567890@txt.att.com" />
        </phones>
    </PhoneNotificationsSection>
Run Code Online (Sandbox Code Playgroud)

然后我想在我的appSettings消费代码中,能够编写这样的东西(伪代码):

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

我做了足够的研究,知道我可能需要一些自己的类来实现和/或继承某些Configuration类,以使上述代码成为可能.我只是没有发现任何清楚地演示这种情况以及如何编写代码的东西 - 当我尝试学习整个.NET配置世界时,我的大脑开始受到伤害.任何人都有一些像我正在寻找他们可以共享的代码吗?

configuration app-config config configuration-files appsettings

3
推荐指数
1
解决办法
2492
查看次数