I'd like to explore my object's properties through some kind of introspection. As object.getMembers() always return null it feels like I will have to do it manually. Thankfully someone pointed out to me that, with mixin and __trait I have powerful too to do so...

Anyway, I'm at the stage of handcrafted experiment.

Now I'm trying to (manually so far) write some method which can return any property through a name (code below) but it fails because "Object" is not a catch all which can be int as well .. object!

How would you go about fixing, making the following code work?
(it doesn't work because ABC() can't become an 'object delegate()' but how would I make a generic method otherwise?)
==================================
class Foo
{
   immutable static members = [__traits(derivedMembers, Foo)];

   private int _abc;
   @property public int ABC() { return _abc; }
   @property public void ABC(int value) { _abc = value; }

   private Foo _foo;
   @property public Foo FOO() { return _foo; }
   @property public void FOO(Foo value) { _foo = value; }

   Object delegate()[string] getmembers;

   this()
   {
       getmembers["ABC"] = delegate Object() { return ABC(); };
       getmembers["FOO"] = delegate Object() { return FOO(); };
   }
}
==================================

Reply via email to