5

In java I have the enum

package com.acme.common;

// In java world
public enum FooEnum {
    AValue,
    AnotherValue
}

This is used throughout the code in Java, e.g.

// In java world
public class Bar {
    void setFoo(FooEnum value) { 
       // ...  
    }
}

This is getting mapped to a class in C# which inherits Java.Lang.Enum as follows:

// Now in C# generated bindings 
// I want this to be a CLR Enum instead
public sealed partial class FooEnum : global::Java.Lang.Enum 
{ 
   // ... 
}   
// C# generated class uses Java.Lang.Enum type for getter and setter
// But I want FooEnum to be clr enum
public partial class Bar 
{        
   public FooEnum Foo { get; set; }
} 

I would like to map this to a C# enum instead using the EnumFields.xml, but no idea how to.

I googled Xamarin Android EnumFields and found a few results, and have read the Xamarin Android Binding walthrough but still not sure quite how to do this ...

Matt
  • 4,612
  • 1
  • 24
  • 44
Dr. Andrew Burnett-Thompson
  • 20,980
  • 8
  • 88
  • 178

1 Answers1

5

First you have define your Enums in EnumFields.xml how they will appear in C#

<mapping jni-class="com/acme/common/FooEnum " clr-enum-type="Com.Acme.Common.FooEnum">
    <field jni-name="AValue" clr-name="AValue" value="0" />
    <field jni-name="AnotherValue" clr-name="AnotherValue" value="1" />
</mapping>

Then you need to edit EnumMethods.xml for all Methods that consume this Enum

<mapping jni-class="com/skobbler/ngx/map/realreach/SKRealReachSettings">
    <method jni-name="getFoo" parameter="return" clr-enum-type="Com.Acme.Common.FooEnum" />
    <method jni-name="setFoo" parameter="measurementUnit" clr-enum-type="Com.Acme.Common.FooEnum" />
</mapping>
Matt
  • 4,612
  • 1
  • 24
  • 44