0

I am creating a binding library for Xamarin.Android from a java AAR file.

Here is the code actually generated after the compilation :

   public interface IParent
   {
   }

   public interface IChild : IParent
   {
   }

   public interface IGetter
   {
       IParent Attribute { get; }
   }

   public class MyClass : IGetter
   {
       public IChild Attribute { get; }    //Not allowed in C# but allowed in Java
   }

The generated code is the basic translation from Java to C#, but is not valid and does not compile.

I would like to modify the Metadata.xml file (or any other) to tell the compilator to generate the following code instead :

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

How could I do please ? I have read the documentation but can't achieve it :-(

Thanks a lot for any help !!

Maxime Esprit
  • 705
  • 1
  • 8
  • 29
  • From [managedReturn](https://learn.microsoft.com/en-us/xamarin/android/platform/binding-java-library/customizing-bindings/java-bindings-metadata#managedreturn), you can try to change return type to `IParent` in `MyClass` class. – Cherry Bu - MSFT Jul 01 '21 at 02:40
  • @CherryBu-MSFT Thank you ! If I change the Attribute type from IChild to IParent in MyClass, I will loose data isn't it ? I will not be able to call IParent methods without casting variables which seems to be impossible in the binding project. I will test it, and keep you informed – Maxime Esprit Jul 01 '21 at 07:03
  • yes, you can try to test it, Looking forward to your feedback. – Cherry Bu - MSFT Jul 02 '21 at 08:58

0 Answers0