Reflection: is type an inner class

Tyler Jameson Little beatgammit at gmail.com
Sat Oct 20 19:46:57 PDT 2012


I got it working using compiles:

     A a = new A;
     foreach (i, type; typeof(A.tupleof)) {
         enum name = A.tupleof[i].stringof[1 + A.stringof.length +
2 .. $];
         static if (__traits(compiles, mixin("A." ~ 
type.stringof))) {
             mixin("a." ~ name) = a.new type;
         } else {
             mixin("a." ~ name) = new type;
         }
     }

It's pretty hacky, but it seems to work. I'd be very interested 
in a cleaner solution, but this works for now.


More information about the Digitalmars-d-learn mailing list