Value: Don't try to marshal if type has no StructLayout

If the StructLayout is not set, StructureToPtr will throw an exception.
In these cases the type is probably wrapped using a handle and thus
needs no update.
This commit is contained in:
Stephan Sundermann 2014-06-21 17:05:32 +02:00 committed by Bertrand Lorentz
parent 1fab57eeac
commit 280087e431

View file

@ -576,6 +576,10 @@ namespace GLib {
if (GType.Is (type, GType.Boxed) && !(val is IWrapper)) { if (GType.Is (type, GType.Boxed) && !(val is IWrapper)) {
MethodInfo mi = val.GetType ().GetMethod ("Update", BindingFlags.NonPublic | BindingFlags.Instance); MethodInfo mi = val.GetType ().GetMethod ("Update", BindingFlags.NonPublic | BindingFlags.Instance);
IntPtr boxed_ptr = g_value_get_boxed (ref this); IntPtr boxed_ptr = g_value_get_boxed (ref this);
if (mi == null && !val.GetType ().IsDefined (typeof(StructLayoutAttribute), false))
return;
if (mi == null) if (mi == null)
Marshal.StructureToPtr (val, boxed_ptr, false); Marshal.StructureToPtr (val, boxed_ptr, false);
else else