Cinchoo – Hierarchical INI sections, Part 9

In this section, I’ll talk about another important feature Cinchoo framework provides in reading INI file is that the support of  Hierarchical INI sections. It gives the flexibility of organizing the INI sections in hierarchical way. An INI section can have another INI subsection in it. Here is how you can do it using Cinchoo framework,

;This is a test nested INI file.
;To test its functionality.

[CORPORATIONS]

[CORPORATIONS/FINANCE]
CORP1=JP Morgan Chase
COPR2=Morgan Stantley

[CORPORATIONS/TECHNOLOGY]
CORP1=Google
COPR2=Apple

In the above sample INI file, the Hierarchical sections are given with ‘/’ separator. ‘CORPORATIONS’ section contains ‘FINANCE’ and ‘TECHNOLOGY’ subsections. There are couple ways, we can access them programmatically

using (ChoIniDocument iniDocument = ChoIniDocument.Load(@"C:\Temp\NestedIniSection.ini"))
{
    Console.WriteLine(iniDocument["CORPORATIONS/TECHNOLOGY"]["CORP1"]);
    Console.WriteLine(iniDocument["CORPORATIONS"].GetSection("TECHNOLOGY")["CORP1"]);
}
About these ads

5 responses to “Cinchoo – Hierarchical INI sections, Part 9

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

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: