digitalmars.D.learn - Probably a real simple compile-time reflection question?
- WhatMeWorry (36/36) Jul 09 2016 class C
- Adam D. Ruppe (6/9) Jul 09 2016 What are you doing to get myClassMembers?
class C
{
this(){ _i = 0; _j = 0; }
void setVar(int i) { _i = i; }
int getVar() { return _i; }
int _i;
int _j;
}
writeln("C");
foreach( i, str; myClassMembers)
{
writeln(" member ", i, " = ", str);
TypeInfo ti = typeid(str);
writeln(" type id is ", ti);
writeln(" type is ", typeof(str).stringof);
}
C
member 0 = __ctor
type id is immutable(char)[]
type is string
member 1 = _i
type id is immutable(char)[]
type is string
member 2 = setVar
type id is immutable(char)[]
type is string
member 3 = getVar
type id is immutable(char)[]
type is string
. . .
the same all the way through the class
I'm trying to get at least the type int for the _i member? Also,
is there a way to get __traits(allMembers to work recursively?
Say, with struct containing structs.
Thanks,
kyle
Jul 09 2016
On Saturday, 9 July 2016 at 21:12:24 UTC, WhatMeWorry wrote:foreach( i, str; myClassMembers)What are you doing to get myClassMembers? If it is __traits(allMembers), it just gives you the *names* of the members. To get the actual thing, you then do __traits(getMember, object, str) and can check the type of that.Also, is there a way to get __traits(allMembers to work recursively? Say, with struct containing structs.You can always just call it recursively once you get the member :)
Jul 09 2016








Adam D. Ruppe <destructionator gmail.com>