我在app.config文件中有一个
部分<OurType>
<sometype typename = "type1" Iscolor="true"/>
<sometype typename = "type2" Iscolor="false"/>
</Ourtype>
我需要做的是将这些值汇总到我的域对象中,该对象在
下面Class OurType
{
public string TypeName{get;set;}
public string IsColor{get;set;}
}
我想做点什么
list<OurType> obj = ConfigurationManager.GetCollection(Something)
将读取该部分的配置部分,然后填充List。
如何使用自定义配置?
由于
我正在使用C#3.0和dot net framework 3.5
答案 0 :(得分:4)
最简单的方法?在Codeplex上查看Visual Studio 2005和2008的Configuration Section Designer加载项。它为您提供了一个很好的用户界面,并生成所有棘手的配置类和XML模式,以便在您的配置部分为您启用Visual Studio智能感知 - 所有这些都非常简洁。
看看吧!
如果您想“手动”执行此操作,请务必查看Jon Rista关于CodeProject上.NET 2.0配置的三部分系列。
强烈推荐,写得很好,非常有帮助!
马克