From 58fb7aa3783bb4e60d73590878399b641af1e2e1 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Thu, 15 May 2014 15:53:22 -0400 Subject: [PATCH] Variant: Add wrapper for g_variant_new_array() --- glib/Variant.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/glib/Variant.cs b/glib/Variant.cs index 4dbdf4593..5e05d6510 100644 --- a/glib/Variant.cs +++ b/glib/Variant.cs @@ -146,6 +146,22 @@ namespace GLib { return new Variant (g_variant_new_tuple (native, new UIntPtr ((ulong) children.Length))); } + [DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)] + static extern IntPtr g_variant_new_array (IntPtr child_type, IntPtr[] children, UIntPtr n_children); + + public static Variant NewArray (VariantType type, Variant[] children) + { + if (children == null) + return new Variant (g_variant_new_array (type.Handle, null, new UIntPtr (0ul))); + + IntPtr[] native = new IntPtr[children.Length]; + for (int i = 0; i < children.Length; i++) + native[i] = children[i].Handle; + + return new Variant (g_variant_new_array (type == null ? (IntPtr) null : type.Handle, + native, new UIntPtr ((ulong) children.Length))); + } + [DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)] static extern bool g_variant_get_boolean (IntPtr handle);