haXe Forum > iterate class
-
Yann Sep 07 at 17:54
A small question, is it possible to iterate all class variables ?
for exemple, if a I have a class like this :class ItClass { public var onething:String; public var twothing:String; public var threething:Int; public function new() { onething = "un"; twothing = "deux"; threething = 3; } }
is it possible to retrieve the three properties with an instance of ItClass ? (the best would be to have the property, the type and the value of, if it is set) !
-
Andy Li Sep 08 at 07:54
Check out Type, there is a "getInstanceFields" function.
-
Yann Sep 13 at 11:19
Thanks Andy, but there's still a problem for me.
With Type.getInstanceFields (myclass), I'm able to find all fields, but how can I access to those fields in an instance of myclass.
In Flash, I would do myInstance[field], but it doesn't work here... -
Yann Sep 13 at 11:32
it's ok, I've just found it ! It is with the Reflect class :)
< Prev
| Page 1 / 1 |
Next >