调用镜像全局函数



我正在我的库中搜索所有全局注释函数:

@MyAnnotation()
String func(arg1, arg2) => "test";
main() {
    var routines = m.currentMirrorSystem().findLibrary(#my.lib).declarations.values
      .where((m.DeclarationMirror dm) =>
        dm is m.MethodMirror && dm.metadata.map((m.InstanceMirror im) => im.reflectee)
            .any((refl) => refl is MyAnnotation)
      );
     // this works all ok
}

现在我有了带注释函数的List<DeclarationMirror>。但我需要稍后调用它。ClosureMirror有invoke方法,但我看不到任何方法可以为我的MethodMirror或Symbol例程获得它。我不能只使用新的ClosureMirror(func),因为我有几十个带注释的函数,而且我不知道每个名字。此外,我没有任何ClassMirror或InstanceMirror。

所以问题是,如何通过其Symbol或MethodMirror调用全局镜像函数。

  m.MethodMirror f = routines[0];
    (f.owner as m.LibraryMirror).invoke(f.simpleName, ['a', 'b']);

最新更新