Cinchoo – Reading Nested INI files, Part 2

ChoIniDocument

In this section, I’ll talk about one of the most important feature Cinchoo framework provides in reading INI file is that the support of  Nested INI files. It gives the flexibility of breaking down large INI file into multiple small and manageable INI files. Here is how you can do it using Cinchoo framework,

Nested INI files can be setup as below

Main.ini file

;This is a test INI file.

[PRODUCT]
VERSION=1.002
COMAPNY=NAG Groups LLC

[INCLUDE("C:\Temp\TestInclude.ini")]

[ENVIRONMENT]
VERSION=1.0.0.1
PATH=C:\WINDOWS

In main.ini file, we included TestInclude.ini file using [INCLUDE] tag. Tag is case-sensitive. Also the path can specified as absolute/relative path.

TestInclude.ini file

[SOFTWARE]
OS1=MAC
OS2=Windows7

Loading Main.ini file using ChoIniDocument.Load() will load all the included INI files and build the tree in memory seamlessly.

static void Main(string[] args)
{
    using (ChoIniDocument iniDocument = ChoIniDocument.Load(@"C:\Temp\TestIni1.ini"))
    {
        Console.WriteLine(iniDocument.ToString());
    }
}

PS: Make sure all the main as well as included INI files contains distinct INI sections (no duplicate section allowed). Otherwise load will fails with exception.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s