Using the result of Type.getClassFields ()

How can I use the static field names returned getClassFields()?

Typeby itself does not have any functions related to this, and if you use Reflectlike this in the field name returned above:

trace(Reflect.field(Type.createEmptyInstance(Type.resolveClass(...)), fieldName));

... You get:

TypeError: Error # 1010: The term is undefined and has no properties.

My goal is to get the value of a static field using the class name given dynamically, for example. How can I get "hi"from:

class Blah {
    public static var test:String="hi";
}

... when I don't know Blah in advance?

Launching Haxe 3.2.1.

+4
source share
1 answer

This should work:

var cl = Type.resolveClass("Blah");
trace(Reflect.field(cl, "test"));

Class<T>, createEmptyInstance() . Reflect.field() .

, Blah . , - - . DCE, @:keep.

+5

All Articles