public void GetBooleanList()
    {
        bool [] expected = new bool [] { true, false, false, true };

        CollectionAssert.AreEqual(expected, test_keyfile.GetBooleanList("Group1", "BoolList"));
    }
Beispiel #2
0
    static void Main()
    {
        GKeyFile key_file = new GKeyFile();

        key_file.SetComment(null, null, String.Format("This file was autogenerated by sample.cs on {0}", DateTime.Now));
        key_file.SetString("General", "sKey0", "that's the string value associated to the sKey0");
        key_file.SetComment("General", null, "A comment for the General group");
        key_file.SetComment("General", "sKey0", "A comment for the sKey0 key");
        key_file.SetStringList("Lists", "sList", new string [] { "item0", "item1", "item2", "lastitem" });
        key_file.SetBoolean("SingleValues", "aBool", true);
        key_file.SetBoolean("SingleValues", "anotherBool", false);
        key_file.SetString("SingleValues", "aString", "this is _not_ a string");
        key_file.SetInteger("SingleValues", "anInt", 42);
        key_file.SetDouble("SingleValues", "aDouble", Math.PI);
        key_file.SetComment("SingleValues", "aDouble", "Change this at the time the square became the new circle");
        key_file.Save("mysamplefile.ini");

        key_file = new GKeyFile("mysamplefile.ini");
        key_file.RemoveComment("SingleValues", "aDouble");
        key_file.SetBooleanList("Lists", "bools", new bool [] { true, false, false, true });
        key_file.SetIntegerList("Lists", "ints", new int [] { 0, 1, 2, -3, -5 });
        key_file.SetDoubleList("Lists", "doubles", new double [] { Math.PI, Math.Sqrt(2) });

        foreach (string group in key_file.GetGroups())
        {
            Console.WriteLine("\t" + group);
            foreach (string key in key_file.GetKeys(group))
            {
                Console.WriteLine("\t\t" + key);
            }
        }
        Console.WriteLine(key_file.HasGroup("Foo"));
        Console.WriteLine(key_file.HasGroup("General"));
        Console.WriteLine(key_file.HasKey("General", "sKey0"));
        Console.WriteLine(key_file.HasKey("General", "sKey1"));
        try {
            key_file.GetValue("foo", "bar");
        } catch (GLib.GException e) {
            Console.WriteLine(e);
        }
        foreach (string val in key_file.GetStringList("Lists", "sList"))
        {
            Console.WriteLine(val);
        }

        foreach (int i in key_file.GetIntegerList("Lists", "ints"))
        {
            Console.WriteLine(i);
        }

        foreach (double d in key_file.GetDoubleList("Lists", "doubles"))
        {
            Console.WriteLine(d);
        }

        foreach (bool b in key_file.GetBooleanList("Lists", "bools"))
        {
            Console.WriteLine(b);
        }

        key_file.Save("mysamplefile2.ini");

        key_file = new GKeyFile("mysamplefile.ini");
        key_file.RemoveGroup("General");
        key_file.Save("mysamplefile3.ini");
    }