Simplest possible key/value pair file parsing in .NET

前端 未结 5 1728
闹比i
闹比i 2021-01-17 19:07

My project requires a file where I will store key/value pair data that should be able to be read and modified by the user. I want the program to just expect the keys to be t

5条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-17 19:17

    I don't know of any builtin class to parse ini file. I've used nini when needed to do so. It's licensed under the MIT/X11 license, so doesn't have any issue to be included in a closed source program.

    It's very to use. So if you have a Settings.ini file formatted this way:

    [Configuration]
    Name = Jb Evain
    Phone = +330101010101
    

    Using it would be as simple as:

    var source = new IniConfigSource ("Settings.ini");
    var config = source.Configs ["Configuration"];
    
    string name = config.Get ("Name");
    string phone = config.Get ("Phone");
    

提交回复
热议问题