【发布时间】:2012-08-06 21:59:27
【问题描述】:
我想定义一个 app.config 部分,作为一个简单的IDictionary<string, IDictionary<string, string>>,在 app.config 文件中看起来像这样:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="ServiceInstances" type="MyProject.Configuration, MyProject"/>
</configSections>
<ServiceInstances>
<ServiceInstance name="service1">
<kvp key="key1" value="value1"/>
<kvp key="key2" value="value2"/>
</ServiceInstance>
<ServiceInstance name="service2">
<kvp key="key3" value="value3"/>
<kvp key="key2" value="value2"/>
</ServiceInstance>
</ServiceInstances>
</configuration>
我看到的所有教程似乎都很深入,我只是在寻找一种快速而肮脏的方法来做到这一点:
IDictionary<string, string> foo = Configuration.GetDictionary("service1");
IDictionary<string, string> bar = Configuration.GetDictionary("service2");
看起来这应该是几行代码,但教程似乎不必要地复杂化了它。有没有一个快速的答案,如果有,有人可以告诉我它应该是什么样子吗?
【问题讨论】:
标签: c# app-config custom-configuration