Dart Angular 2 annotation 它们是如何工作的?
Dart Angular 2 annotation how do they work?
我目前正在玩 Angular 2.
的 Dart 版本
我看到图书馆使用了很多元数据,例如 @Component
。
我想知道这些指令是如何工作的?
我继续 http://www.darlang.org。他们解释了如何定义注释,但没有解释如何使用它来构造一个对象,就像在 angular.io.
中所做的那样
谁能解释一下魔法是如何运作的?
在 Dart 中,注释本身除了存在于添加它们的代码元素旁边之外什么都不做。
在运行时间:
您可以使用 dart:mirrors
查询导入的库中的元素,例如字段、函数、类、参数...这些注释。
dart:mirrors
不鼓励用于浏览器应用程序。在这种情况下,您可以使用具有非常相似功能的 reflectable 包。
另请参阅:
- https://www.dartlang.org/articles/reflection-with-mirrors/
- https://api.dartlang.org/1.14.1/dart-mirrors/dart-mirrors-library.html
- https://whosebug.com/search?q=%5Bdart-mirrors%5D+annotations
在构建时
您可以通过pub serve
和pub build
.
创建一个转换器并在pubspec.yaml
中将其注册为运行
在这种情况下,Dart 分析器可用于查询源文件中的注释,并且像 Angular 一样,将构建步骤中的源代码修改为 add/replace/remove 任意代码。
有关变压器的更多详细信息
- https://www.dartlang.org/tools/pub/assets-and-transformers.html
- https://www.dartlang.org/tools/pub/transformers/
- https://www.dartlang.org/tools/pub/transformers/examples/
- https://www.dartlang.org/tools/pub/transformers/aggregate.html
- https://pub.dartlang.org/packages/code_transformers
我目前正在玩 Angular 2.
的 Dart 版本我看到图书馆使用了很多元数据,例如 @Component
。
我想知道这些指令是如何工作的?
我继续 http://www.darlang.org。他们解释了如何定义注释,但没有解释如何使用它来构造一个对象,就像在 angular.io.
中所做的那样谁能解释一下魔法是如何运作的?
在 Dart 中,注释本身除了存在于添加它们的代码元素旁边之外什么都不做。
在运行时间:
您可以使用 dart:mirrors
查询导入的库中的元素,例如字段、函数、类、参数...这些注释。
dart:mirrors
不鼓励用于浏览器应用程序。在这种情况下,您可以使用具有非常相似功能的 reflectable 包。
另请参阅:
- https://www.dartlang.org/articles/reflection-with-mirrors/
- https://api.dartlang.org/1.14.1/dart-mirrors/dart-mirrors-library.html
- https://whosebug.com/search?q=%5Bdart-mirrors%5D+annotations
在构建时
您可以通过pub serve
和pub build
.
创建一个转换器并在pubspec.yaml
中将其注册为运行
在这种情况下,Dart 分析器可用于查询源文件中的注释,并且像 Angular 一样,将构建步骤中的源代码修改为 add/replace/remove 任意代码。
有关变压器的更多详细信息
- https://www.dartlang.org/tools/pub/assets-and-transformers.html
- https://www.dartlang.org/tools/pub/transformers/
- https://www.dartlang.org/tools/pub/transformers/examples/
- https://www.dartlang.org/tools/pub/transformers/aggregate.html
- https://pub.dartlang.org/packages/code_transformers