diff --git a/glib/Variant.cs b/glib/Variant.cs index 1860e527a..cce7bcbc7 100644 --- a/glib/Variant.cs +++ b/glib/Variant.cs @@ -162,10 +162,24 @@ namespace GLib { [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 (Variant[] children) + { + if (children == null) { + throw new ArgumentNullException ("children", "To create an empty array use NewArray (VariantType., null)"); + } + + return NewArray (null, 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))); + if (children == null) { + if (type == null) { + throw new ArgumentException ("The type and children parameters cannot be both null"); + } else { + 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++) diff --git a/sample/VariantDemo.cs b/sample/VariantDemo.cs index 5d2f1481e..1c3b47c61 100644 --- a/sample/VariantDemo.cs +++ b/sample/VariantDemo.cs @@ -18,7 +18,7 @@ namespace sample variant = Variant.NewTuple (null); Console.WriteLine (variant.Print (true)); - variant = Variant.NewArray (null, new Variant[] {new Variant ("String 4"), new Variant ("String 5")}); + variant = Variant.NewArray (new Variant[] {new Variant ("String 4"), new Variant ("String 5")}); Console.WriteLine (variant.Print (true)); variant = Variant.NewArray (VariantType.String, null);