dart-lang中的自定义注释/元数据



有人能解释一下Dart中注释的使用吗?

在文档中,我发现了这个例子:

library todo;
class todo {
  final String who;
  final String what;
  const todo(this.who, this.what);
}

然后是

import 'todo.dart';
@todo('seth', 'make this do something')
void doSomething() {
 print('do something');
}

那么,我应该在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, []);
        };
      });
    });
  });
}

最新更新