Xamarin Android library binding, remove override m

2019-04-13 18:31发布

问题:

I am trying to bind an Android PDF library in a Xamarin Android Binding project, but a unnecessary "override" modifier is added to a property:

public partial class ReaderView : global::Android.Widget.AdapterView, [...] {
    // ...

    public override unsafe global::Android.Widget.IAdapter Adapter {
        // Metadata.xml XPath method reference: path="/api/package[@name='com.artifex.mupdfdemo']/class[@name='ReaderView']/method[@name='getAdapter' and count(parameter)=0]"
        [Register ("getAdapter", "()Landroid/widget/Adapter;", "GetGetAdapterHandler")]
        get {
            // ...
        }
        // Metadata.xml XPath method reference: path="/api/package[@name='com.artifex.mupdfdemo']/class[@name='ReaderView']/method[@name='setAdapter' and count(parameter)=1 and parameter[1][@type='android.widget.Adapter']]"
        [Register ("setAdapter", "(Landroid/widget/Adapter;)V", "GetSetAdapter_Landroid_widget_Adapter_Handler")]
        set {
            // ...
        }
    }

    // ...
}

I didn't find anything about adding/removing modifiers like "override", or "virtual" in the documentation.

I tried this without success:

<attr path="/api/package[@name='com.artifex.mupdfdemo']/class[@name='ReaderView']/method[@name='getAdapter' and count(parameter)=0]" name="override">false</attr>
<attr path="/api/package[@name='com.artifex.mupdfdemo']/class[@name='ReaderView']/method[@name='setAdapter' and count(parameter)=1 and parameter[1][@type='android.widget.Adapter']]" name="override">false</attr>

Do you guys have any idea about how to do this?

Edit 1: The Java project is on GitHub: https://github.com/asimmon/MuPDF-for-Android and here is a direct link to the file ReaderView.java.

Edit 2: The Xamarin Binding Project is on GitHub too, you will find the Jar library: https://github.com/asimmon/MuPDF-for-Xamarin-Android

回答1:

The solution is to modify the visibility of the method in Metadata.xml:

<attr 
   path="/api/package[@name='com.artifex.mupdfdemo']/class[@name='ReaderView']/method[@name='getAdapter']"
   name="visibility">public</attr>

This effectively removes the override keyword from your method's signature.