GtkSharp/sample/VariantDemo.cs
Bertrand Lorentz a1636d306b Variant: Add a NewArray (Variant[] children) convenience method
This allows you to avoid ugly calls like "NewArray (null, some_array)"
when you want the child type to be determined by the first element of
the children array.

Also throw specific exceptions when both type and children parameters
would be null.
2014-06-13 13:10:48 +02:00

46 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
using GLib;
namespace sample
{
public class VariantDemo
{
public VariantDemo ()
{
var strv = new string[] {"String 1", "String 2"};
var variant = new Variant (strv);
Console.WriteLine (variant.Print (true));
variant = Variant.NewTuple (new Variant[] {variant, new Variant ("String 3")});
Console.WriteLine (variant.Print (true));
variant = Variant.NewTuple (null);
Console.WriteLine (variant.Print (true));
variant = Variant.NewArray (new Variant[] {new Variant ("String 4"), new Variant ("String 5")});
Console.WriteLine (variant.Print (true));
variant = Variant.NewArray (VariantType.String, null);
Console.WriteLine (variant.Print (true));
var dict = new Dictionary<string, Variant> ();
dict.Add ("strv", new Variant (strv));
dict.Add ("unit", Variant.NewTuple (null));
variant = new Variant (dict);
Console.WriteLine (variant.Print (true));
var asv = variant.ToAsv ();
Console.WriteLine ("strv: " + asv["strv"].Print(true));
Console.WriteLine ("unit: " + asv["unit"].Print(true));
Console.WriteLine ("type: " + variant.Type.ToString ());
}
public static void Main (string[] args)
{
new VariantDemo ();
}
}
}