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 ...
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With