June 14, 2011
I'm writing some manual reflection (a bit more automatism will come later, thanks to __traits and mixin)(hopefully)
There are a few problems with my implementation so far...

- First the implementation:

==== system.reflection.member.d =====
module system.reflection.member;

public:

public enum MemberType
{
   Bool,
   Int,
   Object = 100,
}

class MemberDesc
{
   MemberType mtype;
   string name;

   union
   {
       bool delegate() getbool;
       byte delegate() getyte;
       int delegate() getint;
       Object delegate() getobject;
   }

   this(string name, bool delegate() getbool)
   {
       this.name = name;
       this.mtype = MemberType.Bool;
       this.getbool = getbool;
   }

   this(string name, int delegate() getint)
   {
       this.name = name;
       this.mtype = MemberType.Int;
       this.getint = getint;
   }

   this(string name, Object delegate() getobject)
   {
       this.name = name;
       this.mtype = MemberType.Object;
       this.getobject = getobject;
   }
}
========= test.d =====
module test;

import system.reflection.property;

class 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; }

   MemberDesc[string] getmembers;

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

   override string toString()
   {
       return format("Foo(%s, %s)", ABC, FOO);
   }
}
====================

- now the problems:

1./ "getmembers" is an instance variable (i.e. not static) because.. it contains delegate!
ideally it should be static! how could I have this working with a static "getmembers"?

2./ the very different syntax for the constructor of MemberDesc for ABC and FOO
("&ABC", and "delegate Object() { return FOO(); }") how could I automate that (with mixin, __traits and foreach)

3./ I'd like the "getmembers" declaration and / or initialization being in a (mixin?) template. is that possible? how?

Thanks for any tip(S)! :)