I’m trying to figure out a way to resolve an enum based on the name of the class field name. The idea is to check if the field name of a class type matches a specific declaring type. The following code checks if the declaring type is an enum, and then returns that enum type if possible:
private static function attemptResolveEnum(field:String):Enum<Dynamic>
{
try
{
if (Std.is(Type.resolveEnum(field), Enum))
{
return Type.resolveEnum(field);
}
}
catch
{
return null;
}
}
If I wanted to check to see if the “autoSize” property, an existing property of the TextField
class has its declaring type as Enum
, how would I go about this using the function above?
I did a trace(Type.resolveEnum("openfl.text.TextField.autoSize"));
but that returned null to no surprise…
I don’t even know if Haxe reflection is robust enough to achieve this, but can it be done and if so, what would be a possible solution?