重命名元数据中的接口属性 [英] Rename interface property in Metadata

查看:26
本文介绍了重命名元数据中的接口属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Xamarin.Android 绑定中,我有一个从 Java 包装的接口,如下所示:

In Xamarin.Android Bindings, I have an interface wrapped from Java as follows:

// Metadata.xml XPath interface reference: path="/api/package[@name='com.buyandlarge.core.framework']/interface[@name='IView']"
[Register ("com/buyandlarge/core/framework/IView", "", "BuyAndLarge.Core.Framework.IViewInvoker")]
public partial interface IView : global::Core.Framework.IContextProvider, global::BuyAndLarge.Core.Framework.IHitTestable {


    global::Android.Views.ViewGroup.LayoutParams LayoutParams {
        // Metadata.xml XPath method reference: path="/api/package[@name='com.buyandlarge.core.framework']/interface[@name='IView']/method[@name='getLayoutParams' and count(parameter)=0]"
        [Register ("getLayoutParams", "()Landroid/view/ViewGroup$LayoutParams;", "GetGetLayoutParamsHandler:BuyAndLarge.Core.Framework.IViewInvoker, BuyAndLarge.Core")] get;
        // Metadata.xml XPath method reference: path="/api/package[@name='com.buyandlarge.core.framework']/interface[@name='IView']/method[@name='setLayoutParams' and count(parameter)=1 and parameter[1][@type='android.view.ViewGroup.LayoutParams']]"
        [Register ("setLayoutParams", "(Landroid/view/ViewGroup$LayoutParams;)V", "GetSetLayoutParams_Landroid_view_ViewGroup_LayoutParams_Handler:BuyAndLarge.Core.Framework.IViewInvoker, BuyAndLarge.Core")] set;
    }
}

继承global::Android.Views.View的各种类都实现了这个接口.由于一些奇怪的原因,Xamarin 的 Android.Views.View 实现的属性定义为 public virtual ViewGroup.LayoutParams LayoutParameters { get;放;} 所以我在我的代码中得到了数百个类型 Foo 没有实现 IView.LayoutParams"的错误.

Various classes which inherit global::Android.Views.View implement this interface. For some bizarre reason, Xamarin's implementation of Android.Views.View has the property defined as public virtual ViewGroup.LayoutParams LayoutParameters { get; set; } so I get hundreds of 'The type Foo does not implement IView.LayoutParams' errors in my code.

我想使用 metadata.xml 将 IView.LayoutParams 重命名为 IView.LayoutParameters,但不确定语法.

I'd like to use metadata.xml to rename IView.LayoutParams to IView.LayoutParameters, but not sure of the syntax.

我已经试过了:

<attr path="/api/package[@name='com.buyandlarge.core.framework']/interface[@name='IView']/method[@name='getLayoutParams' and count(parameter)=0]" name="managedName">LayoutParameters</attr>
<attr path="/api/package[@name='com.buyandlarge.core.framework']/interface[@name='IView']/method[@name='setLayoutParams' and count(parameter)=1 and parameter[1][@type='android.view.ViewGroup.LayoutParams']]" name="managedName">LayoutParameters</attr>

但没有成功......有什么想法吗?

but no success ... Any ideas?

推荐答案

哈,我想通了!走我!

使用 name="propertyName" 您可以更改为接口或类生成的属性.元数据变成

Using the name="propertyName" you can change the generated property for an interface or class. The metadata becomes

  <!-- Rename IView.LayoutParams to LayoutParameters to be consistent with Android base classes -->
  <attr path="/api/package[@name='com.buyandlarge.core.framework']/interface[@name='IView']/method[@name='getLayoutParams' and count(parameter)=0]" 
        name="propertyName">LayoutParameters</attr>

  <attr path="/api/package[@name='com.buyandlarge.core.framework']/interface[@name='IView']/method[@name='setLayoutParams' and count(parameter)=1 and parameter[1][@type='android.view.ViewGroup.LayoutParams']]" 
        name="propertyName">LayoutParameters</attr>

属性改名了,天已经保存了^_^

The property is renamed, and the day has been saved ^_^

这篇关于重命名元数据中的接口属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆