使用自定义配置读取ConfigurationSection值并表示为域对象(C#3.0) [英] Reading ConfigurationSection value using custom configuration and represent into domain object(C#3.0)

查看:179
本文介绍了使用自定义配置读取ConfigurationSection值并表示为域对象(C#3.0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在app.config文件中有一个部分

I have in the app.config file a section as

<OurType>
 <sometype typename = "type1" Iscolor="true"/>
 <sometype typename = "type2" Iscolor="false"/>
</Ourtype>

我需要做的就是将此值映射到我的域对象中,如下所示>

What I need to do is to polulate this values into my domain object which is as under

Class OurType
{

  public string TypeName{get;set;}
  public string IsColor{get;set;}
}

我想做

list< OurType> obj = ConfigurationManager.GetCollection(Something),它将读取该部分的配置部分,然后填充列表。

list<OurType> obj = ConfigurationManager.GetCollection(Something) which will read the configuration section of that portion and then populate the List.

如何使用自定义配置?

谢谢

我正在使用C#3.0和点网框架3.5

I am using C#3.0 and dot net framework 3.5

推荐答案

最简单的方法?在Codeplex上查看用于Visual Studio 2005和2008的配置部分设计器加载项。它为您提供了一个不错的用户界面,并生成了所有这些棘手的配置类和XML模式,从而使您的配置部分中的Visual Studio intellisense变得非常整洁和轻松。

The easiest way? Check out the Configuration Section Designer add-in for Visual Studio 2005 and 2008 up on Codeplex. It gives you a nice UI to work with, and generates all those thorny configuration classes and a XML schema to enable Visual Studio intellisense in your config sections for you - all very neatly and easily.

签出!

如果您想手工做,请务必签出乔恩·里斯塔(Jon Rista)在CodeProject上的.NET 2.0配置的三部分系列。

If you want to do it "by hand", make sure to check out Jon Rista's three-part series on .NET 2.0 configuration up on CodeProject.

  • Unraveling the mysteries of .NET 2.0 configuration
  • Decoding the mysteries of .NET 2.0 configuration
  • Cracking the mysteries of .NET 2.0 configuration

强烈推荐,写得很好并且非常

Highly recommended, well written and extremely helpful!

马克

这篇关于使用自定义配置读取ConfigurationSection值并表示为域对象(C#3.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆