Skip to content

Instantly share code, notes, and snippets.

@yinyin
Last active June 14, 2017 19:13
Show Gist options
  • Save yinyin/abdebadd7909d1e4f1fa92a63ef0e4c3 to your computer and use it in GitHub Desktop.
Save yinyin/abdebadd7909d1e4f1fa92a63ef0e4c3 to your computer and use it in GitHub Desktop.
Retrieving annotated metadata
import 'dart:mirrors';
class ToDo {
final String who;
final String what;
const ToDo(this.who, this.what);
String toString() => "ToDo[${this.who}: ${this.what}]";
}
@ToDo('seth', 'make this do something')
void doSomething() {
print('do something');
}
void main() {
InstanceMirror instanceMirror = reflect(doSomething);
ClosureMirror colsureMirror = (instanceMirror as ClosureMirror);
int count = 0;
for (InstanceMirror metaObject in colsureMirror.function.metadata) {
count++;
print("meta ${count}: ${metaObject.reflectee}");
}
print("get ${count} meta objects.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment