EnumAbstractInfo
Runtime information container for enum abstract types.
This class provides runtime introspection capabilities for Haxe enum abstracts, allowing dynamic access to enum field names and their corresponding values. It's particularly useful in UI components that need to display or manipulate enum values dynamically, such as dropdown selects or enum field editors.
The class maintains two parallel arrays:
enumFields
: Contains the string names of enum fieldsenumValues
: Contains the actual values associated with each field
Example usage:
// For an enum abstract like:
// enum abstract MyEnum(Int) {
// var OPTION_A = 1;
// var OPTION_B = 2;
// }
var info = new EnumAbstractInfo(
["OPTION_A", "OPTION_B"],
[1, 2]
);
var fieldName = info.getEnumFieldFromValue(2); // Returns "OPTION_B"
var value = info.createEnumValue("OPTION_A"); // Returns 1
Instance Members
Returns all available enum field names.
Returns | Description |
---|---|
Array<String> | Array of enum field names as strings |
Finds the enum field name corresponding to a given value.
This method performs a reverse lookup, finding the field name that matches the provided value.
Name | Type | Description |
---|---|---|
value |
Dynamic | The enum value to look up |
Returns | Description |
---|---|
Null<String> | The field name if found, null otherwise |
Creates an enum value from its field name.
This method looks up the value associated with the given field name. It's useful for converting string representations back to enum values.
Name | Type | Description |
---|---|---|
name |
String | The enum field name to look up |
Returns | Description |
---|---|
Dynamic | The corresponding enum value if found, null otherwise |
Creates a new EnumAbstractInfo instance.
Name | Type | Description |
---|---|---|
enumFields |
Array<String> | Array of enum field names (e.g., ["OPTION_A", "OPTION_B"]) |
enumValues |
Array<Dynamic> | Array of corresponding values (e.g., [1, 2]) |
Private Members
Array of enum field names as strings. The order corresponds to the order in enumValues.
Array of enum values corresponding to each field. The order corresponds to the order in enumFields.