2
我在尋找我的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
}
現在我有我的註釋功能List<DeclarationMirror>
。但我需要稍後調用它。 ClosureMirror有invoke
方法,但是我看不到任何方法可以爲我的MethodMirror或Symbol的例程獲取此方法。 我不能使用新的ClosureMirror(func),因爲我有幾十個註釋函數,我不知道每個名字。另外我沒有任何ClassMirror或InstanceMirror。
所以問題是,如何通過Symbol或MethodMirror調用全局鏡像函數。
哦,這一個工程: 類AnnotatedRoutine實現function { 最終m.MethodMirror程序; UpgradeScript(this.routine); String call(arg1,arg2)=> (routine.owner as m.LibraryMirror).invoke(routine.simpleName,[arg1,arg2])。reflectee; } markdown here sucks – Vaulter
如果你有不同的所有者,你不需要'm.LibraryMirror',我只是添加它來獲得自動完成。 –