introspection woes (2)

Lloyd Dupont ld-REMOVE at galador.net
Mon Jun 13 06:50:09 PDT 2011


Works a treat!
Thanks for your detailed sample! :)



"Robert Clipsham"  wrote in message news:it5395$2028$1 at digitalmars.com... 

See: http://www.digitalmars.com/d/2.0/traits.html
----
class MyClass
{
     void method1(){}
     void method2(){}
}

import std.stdio;

void main()
{
     foreach (member; __traits(allMembers, MyClass))
         writefln("member: %s", member);

     foreach (member; __traits(derivedMembers, MyClass))
         writefln("derived member: %s", member);
}
----

Instead of writefln() you can append to an array. You can also make this 
a bit more generic with:
----
class MyClass
{
     mixin memberArray!MyClass;
     void method1(){}
     void method2(){}
}

import std.stdio;

mixin template memberArray(T)
{
     immutable static members = [__traits(derivedMembers, T)];
}

void main()
{
     foreach (member; MyClass.members)
         writefln("member: %s", member);
}
----

Hope this helps :)

-- 
Robert
http://octarineparrot.com/


More information about the Digitalmars-d-learn mailing list