2008-04-28 Mike Kestner <mkestner@novell.com>

* glib/Value.cs : Add GParam support and beef up the Boxed
	type marshaling to support types with New methods via reflection.

svn path=/trunk/gtk-sharp/; revision=102064
This commit is contained in:
Mike Kestner 2008-04-28 19:00:48 +00:00
parent d5e5c13a1f
commit 4afdaf6602
2 changed files with 24 additions and 1 deletions

View File

@ -1,3 +1,8 @@
2008-04-28 Mike Kestner <mkestner@novell.com>
* glib/Value.cs : Add GParam support and beef up the Boxed
type marshaling to support types with New methods via reflection.
2008-04-28 Mike Kestner <mkestner@novell.com>
* glib/GType.cs : Add a few missing static fields.

View File

@ -24,6 +24,7 @@ namespace GLib {
using System;
using System.Collections;
using System.Reflection;
using System.Runtime.InteropServices;
[StructLayout (LayoutKind.Sequential)]
@ -313,7 +314,14 @@ namespace GLib {
Type t = GType.LookupType (type);
if (t == null)
throw new Exception ("Unknown type " + new GType (type).ToString ());
return Marshal.PtrToStructure (boxed_ptr, t);
else if (t.IsSubclassOf (typeof (GLib.Opaque)))
return (GLib.Opaque) this;
MethodInfo mi = t.GetMethod ("New", BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);
if (mi == null)
return Marshal.PtrToStructure (boxed_ptr, t);
else
return mi.Invoke (null, new object[] {boxed_ptr});
}
public object Val
@ -340,6 +348,8 @@ namespace GLib {
return (string) this;
else if (type == GType.Pointer.Val)
return (IntPtr) this;
else if (type == GType.Param.Val)
return g_value_get_param (ref this);
else if (type == ManagedValue.GType.Val)
return ManagedValue.ObjectForWrapper (g_value_get_boxed (ref this));
else if (g_type_is_a (type, GType.Object.Val))
@ -380,6 +390,8 @@ namespace GLib {
IntPtr buf = Marshal.AllocHGlobal (Marshal.SizeOf (value.GetType()));
Marshal.StructureToPtr (value, buf, false);
g_value_set_pointer (ref this, buf);
} else if (type == GType.Param.Val) {
g_value_set_param (ref this, (IntPtr) value);
} else if (type == ManagedValue.GType.Val) {
IntPtr wrapper = ManagedValue.WrapObject (value);
g_value_set_boxed (ref this, wrapper);
@ -438,6 +450,9 @@ namespace GLib {
[DllImport("libgobject-2.0-0.dll")]
static extern void g_value_set_object (ref Value val, IntPtr data);
[DllImport("libgobject-2.0-0.dll")]
static extern void g_value_set_param (ref Value val, IntPtr data);
[DllImport("libgobject-2.0-0.dll")]
static extern void g_value_set_pointer (ref Value val, IntPtr data);
@ -476,6 +491,9 @@ namespace GLib {
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_value_get_object (ref Value val);
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_value_get_param (ref Value val);
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_value_get_pointer (ref Value val);