Resolving enum by class field

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?

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 String?

Well I found out you can do this:

Type.createEnum(Type.resolveEnum("openfl.text.TextFieldAutoSize"), obj.autoSize);

Where 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.

Doing this:

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.