2009-04-16 Christian Hoff <christian_hoff@gmx.net>
* glib/Value.cs: Support for additional fundamental GTypes. Invoke constructor of corresponding managed type to convert a GValue into its managed representation and a SetGValue method to do that vice versa. Patch contributed by Sebastian Dröge. svn path=/trunk/gtk-sharp/; revision=131931
This commit is contained in:
parent
005731b75c
commit
8fda284c32
2 changed files with 52 additions and 0 deletions
|
@ -1,3 +1,10 @@
|
|||
2009-04-16 Christian Hoff <christian_hoff@gmx.net>
|
||||
|
||||
* glib/Value.cs: Support for additional fundamental GTypes. Invoke
|
||||
constructor of corresponding managed type to convert a GValue into
|
||||
its managed representation and a SetGValue method to do that vice
|
||||
versa. Patch contributed by Sebastian Dröge.
|
||||
|
||||
2009-04-15 Andrés G. Aragoneses <aaragoneses@novell.com>
|
||||
|
||||
* atk/Makefile.am
|
||||
|
|
|
@ -338,6 +338,47 @@ namespace GLib {
|
|||
return strings;
|
||||
}
|
||||
|
||||
object ToRegisteredType () {
|
||||
Type t = GLib.GType.LookupType (type);
|
||||
ConstructorInfo ci = null;
|
||||
|
||||
try {
|
||||
while (ci == null && t != null) {
|
||||
if (!t.IsAbstract)
|
||||
ci = t.GetConstructor (new Type[] { typeof (GLib.Value) });
|
||||
t = t.BaseType;
|
||||
}
|
||||
} catch (Exception) {
|
||||
ci = null;
|
||||
}
|
||||
|
||||
if (ci == null)
|
||||
throw new Exception ("Unknown type " + new GType (type).ToString ());
|
||||
|
||||
return ci.Invoke (new object[] {this});
|
||||
}
|
||||
|
||||
void FromRegisteredType (object val) {
|
||||
Type t = GLib.GType.LookupType (type);
|
||||
MethodInfo mi = null;
|
||||
|
||||
try {
|
||||
while (mi == null && t != null) {
|
||||
mi = t.GetMethod ("SetGValue", new Type[] { typeof (GLib.Value) });
|
||||
if (mi.IsAbstract)
|
||||
mi = null;
|
||||
t = t.BaseType;
|
||||
}
|
||||
} catch (Exception) {
|
||||
mi = null;
|
||||
}
|
||||
|
||||
if (mi == null)
|
||||
throw new Exception ("Unknown type " + new GType (type).ToString ());
|
||||
|
||||
mi.Invoke (val, new object[] { this });
|
||||
}
|
||||
|
||||
object ToBoxed ()
|
||||
{
|
||||
IntPtr boxed_ptr = g_value_get_boxed (ref this);
|
||||
|
@ -390,6 +431,8 @@ namespace GLib {
|
|||
return (GLib.Object) this;
|
||||
else if (GType.Is (type, GType.Boxed))
|
||||
return ToBoxed ();
|
||||
else if (GType.LookupType (type) != null)
|
||||
return ToRegisteredType ();
|
||||
else if (type == IntPtr.Zero)
|
||||
return null;
|
||||
else
|
||||
|
@ -452,6 +495,8 @@ namespace GLib {
|
|||
IntPtr buf = Marshaller.StructureToPtrAlloc (value);
|
||||
g_value_set_boxed (ref this, buf);
|
||||
Marshal.FreeHGlobal (buf);
|
||||
} else if (GLib.GType.LookupType (type) != null) {
|
||||
FromRegisteredType (value);
|
||||
} else
|
||||
throw new Exception ("Unknown type " + new GType (type).ToString ());
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue