Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# VB.NET
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 Smile | :)
 
PS: I've searched for ways to use INI in smart devices but couldn't find a thing.
Posted 23-Nov-12 21:57pm

1 solution

Rate this: bad
good
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 (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.  
  3. 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
  Permalink  
v2
Comments
ayat abukhadra at 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 at 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)

  Print Answers RSS
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 24 Nov 2012
Copyright © CodeProject, 1999-2014
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