smarter reflection issue
Lloyd Dupont
ld-REMOVE at galador.net
Thu Jun 16 15:15:20 PDT 2011
Hi Jesse, this won't work!
It's my fault in not explaining my problem well though...
I forget to mention something...
I'm using property syntax and try to call the method
Say I have
=====
private int _foo;
@property public int Foo() { return _foo; }
@property public void Foo(int value) { _foo = value; }
=====
if I call MEMBER(MyClass, "Foo")
I'd like to do some static test for "int Foo()" and "void Foo(int)"
So... how will I go on solving that?
"Jesse Phillips" wrote in message news:itdqs4$mv0$1 at digitalmars.com...
MemberDesc MEMBER(T, string memberName)() if(std.traits.hasMember!(T,
memberName))
{
...
}
Lloyd Dupont Wrote:
> 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