谁能给我解释一下 Dart 中注释的使用吗?
在文档中,我找到了这个例子:
library todo;
class todo {
final String who;
final String what;
const todo(this.who, this.what);
}
Run Code Online (Sandbox Code Playgroud)
其次是
import 'todo.dart';
@todo('seth', 'make this do something')
void doSomething() {
print('do something');
}
Run Code Online (Sandbox Code Playgroud)
那么,我应该在 main() 中编写什么来执行 doSomething() 函数呢?
谢谢
就像是
import 'dart:mirrors';
import 'do_something.dart';
import 'todo.dart';
void main() {
currentMirrorSystem().libraries.forEach((uri, lib) {
//print('lib: ${uri}');
lib.declarations.forEach((s, decl) {
//print('decl: ${s}');
decl.metadata.where((m) => m.reflectee is Todo).forEach((m) {
var anno = m.reflectee as Todo;
if(decl is MethodMirror) {
print('Todo(${anno.who}, ${anno.what})');
((decl as MethodMirror).owner as LibraryMirror).invoke(s, []);
};
});
});
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2612 次 |
| 最近记录: |