智能设备中的INI文件?如何使用 ? [英] INI files in smart devices ? how to use ?

查看:84
本文介绍了智能设备中的INI文件?如何使用 ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我试图在基于Wince的设备上使用INI文件,如何使用它?如果有其他选择,我很想听听他们的意见:)

PS:我一直在寻找在智能设备中使用INI的方法,但找不到任何东西.

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.

推荐答案

如今,基于XML的XML解析器序列化和 Data Contract 是现成的工具,非常过时的INI文件没有多大意义.我可能看到的唯一原因是使用旧版INI数据.

INI文件的功能非常简单,并且.NET BCL( http://en.wikipedia.org/wiki/Base_Class_Library [< ^ ])如此强大,以至于我看不到任何问题从头开始实现此功能.我可以看到两种方便的方法:

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. 创建一个类来表示包含两个字符串的复合字典键,一个字符串代表节,另一个代表节中的一个键.对于此类,您需要通过覆盖以下两个函数来定义相等和哈希函数:
    http://msdn.microsoft.com/en-us/library/bsc2ak47.aspx [ ^ ],
    http://msdn.microsoft.com/en-us/library/system.object. gethashcode.aspx [ ^ ].

    我们称之为SectionKey类.

    完成此操作后,该类可以用作实例化通用字典类型System.Collections.Generic.Dictionary<SectionKey, string>的键类型,其中第二个通用参数引入了INI值.请参阅:
    http://msdn.microsoft.com/en-us/library/xfhwa508.aspx [ ^ ].

    逐行读取每个INI文件;识别部分名称(在填充过程中用作当前部分")或键值对,提取键和对.使用当前组合键的实例,从当前节名称和键以及字典的值组成SectionKey实例.

    那是.关闭文件,然后使用生成的字典按部分和键快速(O(1))搜索值.如果要从某些数据组成字典,则将其保存到INI文件是很简单的.这是所有键值对的foreach循环.
  2. 与以前的相同,只有几个字典:顶级字典仅表示各个部分;它的键是代表INI节的字符串,其值是字典Dictionary<string, string>,每个字典代表给定节的所有键值对(在INI格式的意义上).
  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



—SA


这篇关于智能设备中的INI文件?如何使用 ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆