Click here to Skip to main content
13,194,662 members (51,712 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I'm trying to use the INI files for my wince based device, how to use it? and if there's alternatives i would love to hear them :)

PS: I've searched for ways to use INI in smart devices but couldn't find a thing.
Posted 23-Nov-12 20:57pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

These days when XML parsers, XML-based serialization and Data Contract are readily available facilities, very much outdated INI files do not make much sense. The only reason I can possibly see would be the use of legacy INI data.

The functionality of INI files is so simple and the .NET BCL ([^]) is so powerful, that I see no problem in implementing of this functionality from scratch. I can see two convenient ways:

  1. Create a class to represent a compound dictionary key containing two strings, one representing section, another one — a key inside a section. For this class, you would need to define equality and hash function by overriding these two functions:[^],[^].

    Let's call it SectionKey class.

    When this is done, the class can serve as a key type for the instantiation of the generic dictionary type System.Collections.Generic.Dictionary<SectionKey, string>, where the second generic parameter introduced the INI values. Please see:[^].

    Read each INI file line by line; recognize either section name (use it as a "current section" during population procedure) or key-value pair, extract the key and pair. Compose the SectionKey instance out of current section name and key, and the value to the dictionary, with this instance of the composite key.

    That's is. Close the file and use the resulting dictionary for fast (O(1)) search of the value by section and key. If you want to compose the dictionary from some data, saving it to INI file is trivial; this is the foreach loop by all key-value pairs.

  2. Same as previous, only with several dictionaries: top-level dictionary represents the sections only; its key is string representing an INI section, and its values are the dictionaries Dictionary<string, string>, each representing all key-value pairs (in the sense of INI format) of a given section.

ayat abukhadra 25-Nov-12 0:32am
Thank you so much :D , but i've use xml files and it worked for me :D
Sergey Alexandrovich Kryukov 25-Nov-12 11:05am
Great; using XMLs instead would be the best, anyway.
Good luck, call again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171018.2 | Last Updated 24 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100