Variant: Add wrapper to construct "a{sv}" variant

This commit is contained in:
Xavier Claessens 2014-05-15 15:53:54 -04:00
parent cef9b13d72
commit 893703018f

View file

@ -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<string, Variant> dict)
{
VariantType type = VariantType.NewDictionaryEntry (
VariantType.String,
VariantType.Variant);
var pairs = new List<Variant> ();
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);