Xamarin Android绑定不正确的方法覆盖名称

时间:2016-05-03 21:10:45

标签: xamarin xamarin.android

Xamarin.Android绑定中的一个奇怪的问题。我有一个java类定义如下:

// Java world
public abstract class BaseRenderableSeries<TX extends Comparable<TX>, 
          TY extends Comparable<TY>, 
          TRenderPassData extends ISeriesRenderPassData, 
          TDataSeries extends IDataSeries<TX, TY>> 

          implements IRenderableSeries {

    // ... 
    protected abstract IHitProvider<? super TRenderPassData> getHitProvider();
    // ... 
}

Java中的派生类覆盖getHitProvider,如下所示:

public class FastLineRenderableSeries<TX extends Comparable<TX>, TY extends Comparable<TY>> extends XyRenderableSeriesBase<TX, TY, LineRenderPassData> {

    @Override
    protected IHitProvider<? super LineRenderPassData> getHitProvider() {
        return new CompositeHitProvider<>(
             new PointMarkerHitProvider(), 
             new LineHitProvider());
    }
}

在Xamarin.Android中,绑定生成如下:

// Generated C# Binding in BaseRenderableSeries.cs
// 
protected abstract global::Com.Scichart.Charting.Visuals.RenderableSeries.HitTest.IHitProvider RawHitProvider {
    // Metadata.xml XPath method reference: path="/api/package[@name='com.scichart.charting.visuals.renderableSeries']/class[@name='BaseRenderableSeries']/method[@name='getHitProvider' and count(parameter)=0]"
    [Register ("getHitProvider", "()Lcom/scichart/charting/visuals/renderableSeries/hitTest/IHitProvider;", "GetGetHitProviderHandler")] get;
}

Que?该属性已从 HitProvider 重命名为 RawHitProvider 。派生的BaseRenderableSeries类试图覆盖 HitProvider ,但这会导致构建错误。

// Generated bindings in FastLineRenderableSeries.cs
protected override unsafe global::Com.Scichart.Charting.Visuals.RenderableSeries.HitTest.IHitProvider HitProvider {
    // Metadata.xml XPath method reference: path="/api/package[@name='com.scichart.charting.visuals.renderableSeries']/class[@name='FastLineRenderableSeries']/method[@name='getHitProvider' and count(parameter)=0]"
    [Register ("getHitProvider", "()Lcom/scichart/charting/visuals/renderableSeries/hitTest/IHitProvider;", "GetGetHitProviderHandler")]
    get {
           // ... 
        }
    }
}
  

FastLineRenderableSeries.HitProvider:没有合适的方法来覆盖

知道为什么吗?什么是Xamarin在这做什么,我怎么能防止它的疯狂?

1 个答案:

答案 0 :(得分:1)

那是因为不支持泛型。也许发生器试图避免可能的名称冲突。

选项a)

尝试更改基类

中的Property的名称
 <attr path="/api/package[@name='com.scichart.charting.visuals.renderableSeries']/class‌​[@name='BaseRenderableSeries']/method[@name='getHitProvider' and count(parameter)=0]" 
       name="managedName">HitProvider</attr>

选项b)

更改子类中属性的名称

<attr path="/api/package[@name='com.scichart.charting.visuals.renderableSeries']/class[@name='FastLineRenderableSeries']/method[@name='getHitProvider' and count(parameter)=0]" 
      name="managedName">RawHitProvider</attr>