LoginSignup
1
0

More than 1 year has passed since last update.

Gtk3アプリ iniファイルの操作

Last updated at Posted at 2021-08-02

Gtk3アプリ iniファイルの操作

NugetからINIFileParserDotNetCoreをインストール

Install-Package INIFileParserDotNetCore 

使用例

 IniFile IniFile1 = new IniFile("test.ini");
 IniFile1["aaa","aaaa"] = "aaaa";
 Console.WriteLine(IniFile1["aaa","aaaa"]);

ソース

using System;
using IniParser;
using IniParser.Model;

/*
 * iniFileParse
 * 
*/

public class IniFile
{
    private string iniFileName = null;
    private FileIniDataParser parser = null;
    private IniData data = null;

    public IniFile(string filePath) {

        parser = new FileIniDataParser();
        iniFileName = filePath;

        try{
            data = parser.ReadFile(iniFileName);
        }
        catch (Exception e)
        {
            if (data == null)
            {
                data = new IniData();
                parser.WriteFile(iniFileName, data);
            }
        }

    }

    public string this[string section,string key] {
        set
        {
            try
            {
                data[section][key] = value;
                parser.WriteFile(iniFileName, data);
            }
            catch (Exception e)
            {
              Console.WriteLine(e.Message);
            }            
        }
        get {
            try
            {
                return data[section][key];
            }
            catch (Exception e)
            {
              Console.WriteLine(e.Message);
            }
        }
    }
}

Gtk3アプリ Dapperのアンダーバーの修正に続く

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0