Executing bundle of functions by their metadata tag in Dart lang -
Executing bundle of functions by their metadata tag in Dart lang -
building on this, want write code run a::
functions refeed same metadata tag.
i tunes codes of previous thread below:
getfunctionmirrorsbytag.dart
class="lang-dart prettyprint-override">library impl; @mirrorsused(metatargets: tag) import 'dart:mirrors'; class tag { final symbol name; const tag(this.name); } list<classmirror> getclassmirrorsbytag(symbol name) { list res = new list(); mirrorsystem ms = currentmirrorsystem(); ms.libraries.foreach((u, lm) { lm.declarations.foreach((s, dm) { dm.metadata.foreach((im) { if ((im.reflectee tag) && im.reflectee.name == name) { res.add(dm); // want replace statement executing returned function } }); }); }); homecoming res; }
main.dart:
class="lang-dart prettyprint-override">library main; import 'getfunctionmirrorsbytag.dart'; import 'extra.dart'; @tag(#foo) printa()=>print('a'); @tag(#foo) printb()=>print('b'); void main() { print(getclassmirrorsbytag(#foo)); }
using above, output is:
class="lang-dart prettyprint-override">[methodmirror on 'printa', methodmirror on 'printb']
class="lang-dart prettyprint-override">@mirrorsused(metatargets: tag) import 'dart:mirrors'; class tag { final symbol name; const tag(this.name); } list getmirrorsbytag(symbol name) { list res = new list(); mirrorsystem ms = currentmirrorsystem(); ms.libraries.foreach((u, lm) { lm.declarations.foreach((s, dm) { dm.metadata.foreach((im) { if ((im.reflectee tag) && im.reflectee.name == name) { res.add(dm); } }); }); }); homecoming res; } @tag(#foo) printa() => print('a'); @tag(#foo) printb() => print('b'); void main() { getmirrorsbytag(#foo).foreach((methodmirror me) { librarymirror owner = me.owner; owner.invoke(me.simplename, []); }); }
dart dart-mirrors
Comments
Post a Comment