Posted by Anuraj on Tuesday, July 15, 2014 Reading time :1 minute
This post is about creating custom configuration sections in .Net. If you search for this topic in internet, you will find lot of code snippets and blog posts(Here is the MSDN link). Unlike that, this post is about a nice tool, .NET Configuration Code Generator which will help you to generate code for you to create custom configuration section. It is a free, open source tool licensed under Apache License 2.0 (Apache).
You can download it from codeplex - http://nconfiggen.codeplex.com/
And once you generate the custom configuration code, you can access it using ConfigurationManager class.
And you need to modify the app.config file to identify the Person section like this. In this ConsoleApplication10.PersonSection is class and ConsoleApplication10 is the assembly, in which class exists. (This is a template I got from the tool)
And if you want to keep your configuration file out of the app.config / web.config, you can do something like this.
And your Person.config file will look like this.
Happy Programming :)
What do you think? I would like to hear your thoughts, suggestions, and questions in the comments section below.