On Tue, 14 Apr 2015 12:52:19 -0400, anonymous <anonym...@example.com>
wrote:
abstract class Refl {
@property abstract string name() const;
immutable(Refl) base() const;
}
class ClassRefl(T) : Refl {
@property override string name() const {
return T.stringof;
}
override immutable(Refl) base() const
{
alias BaseClassesTuple!T base_types;
static if(base_types.length > 0)
{
static immutable(Refl) instance = new
ClassRefl!(base_types[0]);
return instance;
}
else return null;
}
}
static const(Refl) baseRefl = refl.base;
It looks like you ripped this code right out of my current prototype ;)
The problem is though, that having the base() method means that
"ClassRefl!(base_types[0])" must be instantiated, and that template
will also have a base() method, and so will it's base, etc... so
reflecting a single class will automatically reflect all bases. I'm
trying to get away from this behavior and make reflection total opt-in,
meaning that the ClassRefl for the base will only be instantiated if
it's actually used.
Parting thoughts:
I don't know where you're heading with this. But so far I don't see what
it would buy you over std.traits and TypeInfo/TypeInfo_Class.
Because an object-hierarchy is easier to use and self-documenting.
Instead of having to look things up, you just type "Reflection" ".", and
all the choices of what you can do with the object are presented to
you by intellisense.