2004-01-27 Mike Kestner <mkestner@ximian.com>

* glib/TypeConverter.cs : lookup GTypes for boxed value types.
	* glib/Value.cs : fix boxed type handling in object ctor.
	[Fixes #51043]

svn path=/trunk/gtk-sharp/; revision=22555
This commit is contained in:
Mike Kestner 2004-01-27 23:55:13 +00:00
parent 1742a837c1
commit fc42fa2c04
3 changed files with 23 additions and 6 deletions

View File

@ -1,3 +1,9 @@
2004-01-27 Mike Kestner <mkestner@ximian.com>
* glib/TypeConverter.cs : lookup GTypes for boxed value types.
* glib/Value.cs : fix boxed type handling in object ctor.
[Fixes #51043]
2004-01-27 Mike Kestner <mkestner@ximian.com> 2004-01-27 Mike Kestner <mkestner@ximian.com>
* generator/BoxedGen.cs : gen a Value to Boxed explicit cast op. * generator/BoxedGen.cs : gen a Value to Boxed explicit cast op.

View File

@ -7,6 +7,7 @@
namespace GLibSharp { namespace GLibSharp {
using System; using System;
using System.Collections; using System.Collections;
using System.Reflection;
using GLib; using GLib;
/// <summary> /// <summary>
@ -36,14 +37,17 @@ namespace GLibSharp {
return GType.Char; return GType.Char;
if (type.Equals (typeof (uint))) if (type.Equals (typeof (uint)))
return GType.UInt; return GType.UInt;
if (type.IsValueType)
return GType.Pointer;
if (type.IsSubclassOf (typeof (GLib.Object))) if (type.IsSubclassOf (typeof (GLib.Object)))
return GType.Object; return GType.Object;
else if (type.IsSubclassOf (typeof (GLib.Boxed))) if (type.IsValueType) {
return GType.Boxed; PropertyInfo pi = type.GetProperty ("GType");
else if (pi == null)
return GType.None; return GType.Pointer;
else
return (GType) pi.GetValue (null, null);
}
return GType.None;
} }
} }
} }

View File

@ -317,6 +317,9 @@ namespace GLib {
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
static extern void g_value_set_boxed_take_ownership (IntPtr val, IntPtr data); static extern void g_value_set_boxed_take_ownership (IntPtr val, IntPtr data);
[DllImport("libgobject-2.0-0.dll")]
static extern bool g_type_is_a (IntPtr type, IntPtr is_a_type);
IntPtr buf = IntPtr.Zero; IntPtr buf = IntPtr.Zero;
/// <summary> /// <summary>
@ -361,6 +364,10 @@ namespace GLib {
buf = Marshal.AllocHGlobal (Marshal.SizeOf (obj.GetType())); buf = Marshal.AllocHGlobal (Marshal.SizeOf (obj.GetType()));
Marshal.StructureToPtr (obj, buf, false); Marshal.StructureToPtr (obj, buf, false);
g_value_set_pointer (_val, buf); g_value_set_pointer (_val, buf);
} else if (g_type_is_a (type.Val, GLib.GType.Boxed.Val)) {
buf = Marshal.AllocHGlobal (Marshal.SizeOf (obj.GetType()));
Marshal.StructureToPtr (obj, buf, false);
g_value_set_boxed (_val, buf);
} else } else
throw new Exception ("Unknown type"); throw new Exception ("Unknown type");
} }