Friday, August 3, 2012

Simplest possible key/value pair file parsing in .NET


Hi All

Recently i was working on a requirement to pick a value from config file, in order to make the application more flexible. The one commonly used method is to either use the .config file or else go for XML. I cannot dump whole data into .config so i ruled out that option and i don't want to go for the same old XML parsing nodes technique. So i browsed and came across "Nini" (not sure how they got this name :-)). Yeah it is simple to use.


You can define your own file with just a simple syntax of pair key value.Something like :

[Configuration]
Name = Nishant Kumar 
Phone = +44-0123456789

And then you can read the keys as below :

var source = new IniConfigSource ("Settings.ini"); 
var config = source.Configs ["Configuration"]; 
string name = config.Get ("Name"); 
string phone = config.Get ("Phone");

So looks quite simple,Obviously, you need to have a reference to the dll's of Nini. This can be downloaded from

1 comment: