Last active
June 14, 2017 19:13
-
-
Save yinyin/abdebadd7909d1e4f1fa92a63ef0e4c3 to your computer and use it in GitHub Desktop.
Retrieving annotated metadata
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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