【问题标题】:Xamarin binding call methodsXamarin 绑定调用方法
【发布时间】:2014-10-21 21:21:57
【问题描述】:

我已经为我的原始项目创建了一个绑定项目,我已经将我的库添加到了绑定项目。这是我在 ApiDefinition.cs 中的代码:

public partial interface TestInterface1 
{
    [Static,Export ("sum:with:")]
    int TestAdd (int first, int second);
}

我添加了绑定作为对原始项目的引用,但是如何调用 TestAdd() ?我在命名空间中找到了接口,但我不知道如何使用它?

谢谢

【问题讨论】:

  • 不确定你在这里问的是什么,你需要在你的问题中加入更多的上下文。如果你问如何绑定原生库,试试 Objective Sharpie
  • 我也不确定您要做什么。您不能直接在接口上使用方法,除非它引用实现该接口的类。您是否创建了一个类似于“public class SomeClassName : TestInterface1”的类?

标签: binding xamarin


【解决方案1】:

您需要获取一个实现 TestInterface1 的对象的实例。如果您没有这样的东西,您可能想将您的接口更改为一个类,以便您自己实例化一个 TestInterface1 类型的对象?

public class TestInterface1 
{
    [Static,Export ("sum:with:")]
    int TestAdd (int first, int second);
}

然后像这样使用它

var test = new TestInterface1();
var result = test.TestAdd(1,2);

有道理吗?

【讨论】:

    猜你喜欢
    • 2015-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-15
    • 1970-01-01
    • 2014-11-21
    • 1970-01-01
    • 2016-03-05
    相关资源
    最近更新 更多