re: dart wrap all function calls

175 Views Asked by At

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.

0

There are 0 best solutions below