mercredi 30 décembre 2015

Invoke mirrored global function

I'm searching all global annotated functions in my lib:

@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

Now I have List<DeclarationMirror> of my annotated functions. But I need to invoke it later. ClosureMirror has invoke method, but I cannot see any way to get this for my either MethodMirror or Symbol of routine. I cannot use just new ClosureMirror(func) as I have dozens of my annotated functions and I don't know every name. Also I dont have any ClassMirror or InstanceMirror.

So question is, how to invoke global mirrored functions by its Symbol or MethodMirror.





Aucun commentaire:

Enregistrer un commentaire