When using standard enums, it’s easy to create an enum value from a string using the createByName()
method:
enum MyEnum {
Alt1;
}
var alt1 = MyEnum.createByName('Alt1');
How can I do the same using enum abstracts?
Let’s say I have following…
enum abstract MyAbstractEnum(Int) {
var Alt1 = 1;
}
…where I would like to create the MyAbstractEnum.Alt1
from the string “Alt1”?
Has to be done the macro way because abstracts don’t exist at runtime, right?
This code.haxe.org snippet helps me getting the underlying values, and by modifying that snippet I can also get the field names… But I haven’t figured out the rest.
Ideas?
/ Jonas