0

I have a problem with converting Java enum to C# enum when binding a Java native library. I have already tried:

I have class Receipt and enum Status. Enum Status is nested inside Receipt class(Java code):

public class Receipt {

        public enum Status {
        created,
        processing,
        declined,
        approved,
        expired,
        reversed;

    }
    public final Status status; 
}

Class Receipt has a field with Status type. When I try to build it with enum mapping it doesn't generate properly. It generates class Status instead of enum(public sealed partial class Status : global::Java.Lang.Enum) and what is more important it doesn't generate field status for class Receipt at all(public final Status status).

EnumFields.xml

<enum-field-mappings>
    <mapping jni-class="com/cloudipsp/android/Status" clr-enum-type="Com.Cloudipsp.Android.Status">
        <field jni-name="created" clr-name="created" value="0" />
        <field jni-name="processing" clr-name="processing" value="1" />
        <field jni-name="declined" clr-name="declined" value="2" />
        <field jni-name="approved" clr-name="approved" value="3" />
        <field jni-name="expired" clr-name="expired" value="4" />
        <field jni-name="reversed" clr-name="reversed" value="5" />
    </mapping>
</enum-field-mappings>```

I would be grateful for any help.
  • Please add to question whatever `xml` or build instructions you wrote, to tell the mapper what to do. Is there an `EnumFields.xml` for that enum? [I've never done this process; I'm just going by what those links say. Sounds like its up to you to tell the mapper what to do.] – ToolmakerSteve Jul 28 '22 at 01:52
  • @ToolmakerSteve I've added EnumFields.xml content. – Artem Mishenkov Jul 28 '22 at 14:31
  • Hmm. As a test, does it do better if you move enum Status out of Receipt? So isn’t nested. – ToolmakerSteve Jul 28 '22 at 17:39
  • @ToolmakerSteve I was thinking about this option too so I have to modify java code, build .aar file and then rebuild a library. Definitely, I will try. But I was hoping there was any other more straightforward solution to achieve my goal. Thank you for your efforts, I appreciate it. – Artem Mishenkov Jul 28 '22 at 23:06
  • I'm not familiar enough with the topic, but isn't it possible to hand-edit the bindings that are made? The result is a c# file that binds to the java library, right? What happens if you make a change in that c# file? (Ignore if this makes no sense.) – ToolmakerSteve Jul 28 '22 at 23:23
  • 1
    It makes sense, but it seems to be not a good practice for two reasons, first - generated C# code invokes Java code so it's pretty tricky to invoke it properly, second - you will have to hand-edit it each time when you are building a library. I have already modified the source Java code and now it works fine. – Artem Mishenkov Jul 28 '22 at 23:51

0 Answers0