Re: smarter reflection issue
It helped! it's working now! :) Thanks! "Jesse Phillips" wrote in message news:itgg6i$2tf3$1...@digitalmars.com... Lloyd Dupont Wrote: 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? I don't remember how to package these up nicely: void MEMBER(T, string fun)(T m) if(expectedType!(T, fun).valid) { } template expectedType(T, string fun) { private T s; static if(mixin("__traits(compiles, s."~fun~" = 0) && is(typeof(s."~fun~") : int)")) enum valid = true; else enum valid = false; }
Re: smarter reflection issue
Lloyd Dupont Wrote: > 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? I don't remember how to package these up nicely: void MEMBER(T, string fun)(T m) if(expectedType!(T, fun).valid) { } template expectedType(T, string fun) { private T s; static if(mixin("__traits(compiles, s."~fun~" = 0) && is(typeof(s."~fun~") : int)")) enum valid = true; else enum valid = false; }
Re: smarter reflection issue
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...@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); } =
Re: smarter reflection issue
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); > } > = >