回复:飞镖包裹所有功能调用

发布于 2025-02-04 02:00:09 字数 800 浏览 1 评论 0原文

这是这个问题的重复性: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文