回复:飞镖包裹所有功能调用
这是这个问题的重复性: dart:包装所有功能调用。
我刚刚开始了解镜子是什么,并且鉴于我仍然无法对任何帖子发表评论,所以我认为我应该在这里自行提出问题。
他的代码像这样:
class Wrapper{
_wrap(Function f, Symbol s){
var name = MirrorSystem.getName(s);
print('Entering $name');
var result = f();
print('Leaving $name');
return result;
}
}
@proxy
class StoryTellerProxy extends Wrapper implements StoryTeller{
final InstanceMirror mirror;
StoryTellerProxy(StoryTeller storyTeller): mirror = reflect(storyTeller);
@override
noSuchMethod(Invocation invocation) =>
_wrap(() => mirror.delegate(invocation), invocation.memberName);
}
我想知道使用镜子是否会大大增加我的代码库的大小。我希望将其应用于我的API处理程序类,从本质上将所有功能调用与API联系起来,从而在没有200/201作为状态代码的情况下捕获错误和响应。
This is a duplicate of this question: dart: wrap all function calls.
I've just begun to learn what mirrors are and given that I still can't comment on any post, I figured I should just ask it here as a question on its own.
His code went like this:
class Wrapper{
_wrap(Function f, Symbol s){
var name = MirrorSystem.getName(s);
print('Entering $name');
var result = f();
print('Leaving $name');
return result;
}
}
@proxy
class StoryTellerProxy extends Wrapper implements StoryTeller{
final InstanceMirror mirror;
StoryTellerProxy(StoryTeller storyTeller): mirror = reflect(storyTeller);
@override
noSuchMethod(Invocation invocation) =>
_wrap(() => mirror.delegate(invocation), invocation.memberName);
}
I was wondering if using mirrors would render a large increase in my codebase size. I was hoping to apply this to my API handler class to essentially wrap all function calls to the API, catching errors and responses without 200/201 as status codes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论