smarter reflection issue

Lloyd Dupont ld-REMOVE at galador.net
Thu Jun 16 07:26:12 PDT 2011


I have a MemberDesc class which describe a class's members.
I fill it with a template method like that (with GETTER and SETTER some 
other templated method I wrote)
=====
MemberDesc MEMBER(T, string memberName)()
{
    TypeInfo ti = typeid( typeof(__traits(getMember, T, memberName)) );

    Variant function(Object target) getter = null;
    getter = &GETTER!(T, memberName);


    void function(Object target, Variant value) setter = null;
    setter = &SETTER!(T, memberName);

    return new MemberDesc(memberName, ti , getter, setter);
}
=====

And it works except that I don't do any check that the setter / getter 
method exist!

I tried something like that
====
static if( __traits(compiles, __traits(getMember, T, member)) )
{
    getter = &GETTER!(T, memberName);
}
====

but this always fail... mm.. how could I check for the getter?


and i guess it's even harder for the setter!
how about something like that (how to fix it?)
=====
static if( __traits(compiles, __traits(getMember, T, member) = 
typeof(__traits(getMember, T, memberName)).init) )
{
    setter = &SETTER!(T, memberName);
}
=====



More information about the Digitalmars-d-learn mailing list