diff --git a/glib/Variant.cs b/glib/Variant.cs index 674742e6d..ea401af8e 100644 --- a/glib/Variant.cs +++ b/glib/Variant.cs @@ -16,6 +16,7 @@ using System; using System.Runtime.InteropServices; +using System.Collections.Generic; namespace GLib { @@ -170,6 +171,19 @@ namespace GLib { return new Variant (g_variant_new_dict_entry (k.Handle, v.Handle)); } + public Variant (IDictionary dict) + { + VariantType type = VariantType.NewDictionaryEntry ( + VariantType.String, + VariantType.Variant); + + var pairs = new List (); + foreach (var kvp in dict) + pairs.Add (NewDictEntry (new Variant (kvp.Key), NewVariant (kvp.Value))); + + handle = g_variant_ref_sink (NewArray (type, pairs.ToArray ()).Handle); + } + [DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)] static extern bool g_variant_get_boolean (IntPtr handle);