Class Data Members Name Reflection

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jun 10 09:13:30 PDT 2014


Two options: do allMembers and filter it out to only be data 
members, or do some slicing of tupleof.stringof:

S s;
foreach(idx, member; s.tupleof) {
    writeln("Name: ", s.tupleof[idx].stringof[2..$]);
}


The tupleof[idx] inside the loop is important instead of just 
using member because then you get the name, then the slicing is 
because you get:

s.foo

for example, and you want to slice off the "s." to leave just the 
name.


More information about the Digitalmars-d-learn mailing list