Having mirrors returning futures certainly makes sense
No it doesn't (well, at least not to me :-) ). And it will probably be changed, see http://dartbug.com/4633#c17
The way I'd normally do it is by defining noSuchMethod in MagicalDynamicWrapper that will check if there is a method with such a name in the methods map, then call it, and if there is none, it will call the "real" object via reflection.
Check the InvocationMirror
documentation. You can forward method calls using the invokeOn
method:
class Proxy {
var target;
Map<String, Function> overrides;
Proxy(this.target, this.overrides);
noSuchMethod(invocation) {
if (overrides.containsKey(invocation.memberName)) {
return overrides[invocation.memberName]();
} else {
return invocation.invokeOn(target);
}
}
}
Is there a way to get the result of a reflection call synchronously?
No, it isn't. Not right now. You can star http://dartbug.com/4633 if you wish.