将aar库绑定到Xamarin.Android



我正在从AAR库创建一个绑定库,以便生成一个可以在Xamarin.Android项目中使用的dll。

我有一个问题,因为一个Java授权的语法在C#中没有授权

您将如何用C#编写此Java代码?

public interface IParent{
}
public interface IChild extends IParent{
}
public interface IGetter{
IParent getAttribute();
}
public class MyClass implements IGetter{
public IChild getAttribute() {
return null;
}
}

生成的自动绑定文件给了我这个未经授权的结果之王

public interface IParent
{
}
public interface IChild : IParent
{
}

public interface IGetter
{
IParent Attribute { get; }
}
public class MyClass : IGetter
{
public IChild Attribute { get; }    //Not allowed but is the exact Java equivalent
//public IParent Attribute { get; }    //Allowed but not the exact Java equivalent
}

我得到以下错误:

'MyClass' does not implement interface member 'IGetter.Attribute'. 'MyClass.Attribute' cannot implement 'IGetter.Attribute' because it does not have the matching return type of 'IParent'.

我正在考虑创建一个完整的类,在IChild和IPparent之间架起桥梁,但它必须是另一个更合适的解决方案。。。

谢谢@fredrik

这是我在你的评论中找到的解决方案:

public interface IParent
{
}
public interface IChild : IParent
{
}

public interface IGetter<T> where T : IParent
{
T Attribute { get; }
}
public class MyClass : IGetter<IChild>
{
public IChild Attribute { get; }   
}

使用模板确实是解决方案。

最新更新