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>
if (Std.is(Type.resolveEnum(field), Enum))
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?
If it’s a member of a class you’d probably need to create the object, so you can get access to the variable, and then find out it’s type before you can use your function.
But why do you want to do that?
Enums aren’t created at runtime so there’s no need to check at that time,
and if you want access or something why not store in a
Enum<Dynamic> variable instead of
Well I found out you can do this:
obj.autoSize is a constructor, like
LEFT for example since that is a member of the said enum.
I’m just figuring out a way to generate known classes at runtime, not unknown classes.
It’s unfortunate that it looks like I’m going to have to do it all manually.
if (Std.is(Reflect.getProperty(Type.resolveClass("openfl.text.TextField"), "autoSize"), Enum))
just results in false. I’m assuming this is because the Reflect API doesn’t work well with the Type system.