飞镖 - 从使用反射调用的方法获得结果
我正在尝试使用DART的Mirror API动态调用功能。
在通过dowork
方法通过instancemirror
调用时,我如何获得从dowork
方法返回的结果,
class MyData {
String someString;
}
class MyService {
Future<MyData> doWork() async {
print('doing work');
return await Future(() => MyData()..someString = 'my result');
}
}
void main() async {
var instance = MyService();
var mirrror = reflect(instance);
var result = mirrror.invoke(#doWork, []);
}
我可以看到“做工作”
被打印到控制台,所以我知道它是被调用的,但是我正在努力从Invoke
函数中解释结果。
I'm trying to use dart's mirror API to dynamically invoke a function.
How can I obtain the result that's returned from the doWork
method when invoking it via an InstanceMirror
class MyData {
String someString;
}
class MyService {
Future<MyData> doWork() async {
print('doing work');
return await Future(() => MyData()..someString = 'my result');
}
}
void main() async {
var instance = MyService();
var mirrror = reflect(instance);
var result = mirrror.invoke(#doWork, []);
}
I can see that "doing work"
gets printed to the console so I know it's being invoked, but I'm struggling to interpret the result from the invoke
function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该值在属性
Reflectee
中的InstanceMirror
内。这样的事情:The value are inside the
InstanceMirror
in the propertyreflectee
. So something like this: