Skip to content

Commit ec2813a

Browse files
radekdoulikjonpryor
authored andcommitted
[Java.Interop] Additional marshaler lookup (#389)
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`.
1 parent 23372ea commit ec2813a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/Java.Interop/Java.Interop/JniRuntime.JniValueManager.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,20 @@ public JniValueMarshaler GetValueMarshaler (Type type)
527527
if (typeof (IJavaPeerable).GetTypeInfo ().IsAssignableFrom (info)) {
528528
return JavaPeerableValueMarshaler.Instance;
529529
}
530+
531+
JniValueMarshalerAttribute ifaceAttribute = null;
532+
foreach (var iface in info.ImplementedInterfaces) {
533+
marshalerAttr = iface.GetTypeInfo ().GetCustomAttribute<JniValueMarshalerAttribute> ();
534+
if (marshalerAttr != null) {
535+
if (ifaceAttribute != null)
536+
throw new NotSupportedException ($"There is more than one interface with custom marshaler for type {type}.");
537+
538+
ifaceAttribute = marshalerAttr;
539+
}
540+
}
541+
if (ifaceAttribute != null)
542+
return (JniValueMarshaler) Activator.CreateInstance (ifaceAttribute.MarshalerType);
543+
530544
return GetValueMarshalerCore (type);
531545
}
532546

0 commit comments

Comments
 (0)