How to convert a class field name to string

55 views
Skip to first unread message

dja onourside

unread,
Feb 8, 2016, 5:08:20 AM2/8/16
to Haxe
Hello, haxers!
Excuse my noob question, but I want to know the simplest way of tracing public static class field.
For example, I have:
 
class SomeClass
{
    public static var someField: SomeType;
 }

1) var s1: String = ... // I want to get s1 value as "someField"
2) var s2: String = ... // I want to get s2 value as "SomeClass.someField"

dja onourside

unread,
Feb 8, 2016, 2:21:39 PM2/8/16
to Haxe
The solution I'v  found:

var expr: Expr = macro SomeClass.someField;
var fieldName = switch(expr.expr)
 {
       case EField(e, field):field;
       case _: "";
 }
trace(fieldName); //someField

понедельник, 8 февраля 2016 г., 13:08:20 UTC+3 пользователь dja onourside написал:
Reply all
Reply to author
Forward
0 new messages