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 thoughts on “Cinchoo – Hierarchical INI sections, Part 9

  1. Hi,
    I have a problem with this framework.
    If I add to reference Cinchoo and add namespace –
    using Cinchoo.Core.Ini;

    Visual studio show error

    Error 1 The type or namespace name ‘Cinchoo’ could not be found (are you missing a using directive or an assembly reference?)

    Where is problem ?

    1. Your project needs to be build with “.NET framework 4″ instead of “.NET framework 4 Client Profile”. Please go to project properties->Application tab, choose the ‘Target Framework’ as ‘.NET framework 4′. Let me know if that helps.

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