glib: fix NRE regression after interface naming changed

ListBase was throwing a NullReferenceException in DataMarshal() due
to the fact that Reflection was being used to find the adapter name
of the interface generated by the bindings, which has recently
changed [1].

[1] 6cb03440c1
This commit is contained in:
Andrés G. Aragoneses 2013-08-24 00:11:05 +02:00
parent 74b6340d86
commit 6f16031661

View File

@ -168,7 +168,7 @@ namespace GLib {
else if (element_type.IsValueType)
ret = Marshal.PtrToStructure (data, element_type);
else if (element_type.IsInterface) {
Type adapter_type = element_type.Assembly.GetType (element_type.FullName + "Adapter");
Type adapter_type = element_type.Assembly.GetType (InterfaceToAdapterTypeName (element_type));
System.Reflection.MethodInfo method = adapter_type.GetMethod ("GetObject", new Type[] {typeof(IntPtr), typeof(bool)});
ret = method.Invoke (null, new object[] {data, false});
} else
@ -180,6 +180,16 @@ namespace GLib {
return ret;
}
static string InterfaceToAdapterTypeName (Type type)
{
string fullname = type.Namespace;
if (!String.IsNullOrEmpty (fullname)) {
fullname += ".";
}
fullname += type.Name.Substring (1); // IActivatable -> Activatable
return fullname + "Adapter";
}
[DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_free (IntPtr item);