Is it possible to get class of field with null value in haxe?
The function "Type.getClass" gets class of value (setted at runtime), but I need to get class defined in a compilation-time.
Function "getClassFields" returns only names of fields, without classes.
For example:
class MyCls
{
public static var i:Int = null;
public static var s:String = null;
}
trace(Type.getClass(MyCls.i)); // show "null", but I need to get Int
trace(Type.getClass(MyCls.s)); // show "null", but I need to get String
And in my situation I can't to change sources of class MyCls.
Thanks.
Since you need to get the types for null fields, you really need to resort to Haxe's Runtime Type Information (RTTI) (as @ReallylUniqueName recomended).
Now, obviously, there's a catch...
RTTI requires a
@:rttimetadata, but you said you cannot change theMyClsclass to add it. The solution then is do add it through a macro in your build file. For instance, if you're using a.hxmlfile, it should then look like:With this and your own
MyClsdefinition, the output would look like: