smarter reflection issue

Jesse Phillips jessekphillips+D at gmail.com
Fri Jun 17 14:16:02 PDT 2011


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



More information about the Digitalmars-d-learn mailing list