简体   繁体   中英

Binding aar library to Xamarin.Android

I am creating a Binding Library from a AAR lib in order to generate a dll that I would be able to use in a Xamarin.Android project.

I have an issue because of a Java authorized syntaxe which is not authorized in C#

How would you write this Java code in C# ?

   public interface IParent{
   }

   public interface IChild extends IParent{
   }

   public interface IGetter{
       IParent getAttribute();
   }

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

The automatic binding file generated gives me this king of result, which is not authorized

   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
   }

I get the following error :

'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'.

I am thinking about creating a entire class that would do the bridge between IChild and IParent, but it must be another solution more suitable...

Thank you @fredrik

Here is the solution I found thanks to your comment :

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; }   
}

Using templates was indeed the solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM