Reading ConfigurationSection value using custom configuration and represent into domain object(C#3.0)
I have in the app.config file a section as
<OurType>
<sometype typenam开发者_开发知识库e = "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;}
}
I want to do something like
list<OurType> obj = ConfigurationManager.GetCollection(Something)
which will read the configuration section of that portion and then populate the List.
How to do it using custom configuration?
Thanks
I am using C#3.0 and dot net framework 3.5
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.
Check it out!
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!
Marc
精彩评论