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>
* generator/BoxedGen.cs : gen a Value to Boxed explicit cast op.

View File

@ -7,6 +7,7 @@
namespace GLibSharp {
using System;
using System.Collections;
using System.Reflection;
using GLib;
/// <summary>
@ -36,14 +37,17 @@ namespace GLibSharp {
return GType.Char;
if (type.Equals (typeof (uint)))
return GType.UInt;
if (type.IsValueType)
return GType.Pointer;
if (type.IsSubclassOf (typeof (GLib.Object)))
return GType.Object;
else if (type.IsSubclassOf (typeof (GLib.Boxed)))
return GType.Boxed;
else
return GType.None;
if (type.IsValueType) {
PropertyInfo pi = type.GetProperty ("GType");
if (pi == null)
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")]
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;
/// <summary>
@ -361,6 +364,10 @@ namespace GLib {
buf = Marshal.AllocHGlobal (Marshal.SizeOf (obj.GetType()));
Marshal.StructureToPtr (obj, buf, false);
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
throw new Exception ("Unknown type");
}