Skip to content

Commit

Permalink
[Java.Interop] Additional marshaler lookup (#389)
Browse files Browse the repository at this point in the history
Context: #388

Before going to use the proxy object marshaler, try to check the
implemented interfaces of `type` for a custom marshaler.

It can be used in xamarin-android to marshal `IJavaObject` based
objects, which do not implement `IJavaPeerable`.
  • Loading branch information
radekdoulik authored and jonpryor committed Oct 26, 2018
1 parent 23372ea commit ec2813a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Java.Interop/Java.Interop/JniRuntime.JniValueManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,20 @@ public JniValueMarshaler GetValueMarshaler (Type type)
if (typeof (IJavaPeerable).GetTypeInfo ().IsAssignableFrom (info)) {
return JavaPeerableValueMarshaler.Instance;
}

JniValueMarshalerAttribute ifaceAttribute = null;
foreach (var iface in info.ImplementedInterfaces) {
marshalerAttr = iface.GetTypeInfo ().GetCustomAttribute<JniValueMarshalerAttribute> ();
if (marshalerAttr != null) {
if (ifaceAttribute != null)
throw new NotSupportedException ($"There is more than one interface with custom marshaler for type {type}.");

ifaceAttribute = marshalerAttr;
}
}
if (ifaceAttribute != null)
return (JniValueMarshaler) Activator.CreateInstance (ifaceAttribute.MarshalerType);

return GetValueMarshalerCore (type);
}

Expand Down

0 comments on commit ec2813a

Please sign in to comment.