Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

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

1 solution

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 (http://en.wikipedia.org/wiki/Base_Class_Library[^]) 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:
    http://msdn.microsoft.com/en-us/library/bsc2ak47.aspx[^],
    http://msdn.microsoft.com/en-us/library/system.object.gethashcode.aspx[^].

    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:
    http://msdn.microsoft.com/en-us/library/xfhwa508.aspx[^].

    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.


—SA
 
Share this answer
 
v2
Comments
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.
--SA

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900