如何为Dart编写注释 [英] how can I write an annotation for Dart

查看:301
本文介绍了如何为Dart编写注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

  • 实现注释的过程是什么.
  • 如何或实际上什么时候可以激活您开发的注释?

我似乎找不到有关如何编写用于实现.

I can't seem to find an example or tutorial on how to write a class to implement annotations for .

例如,对于Java,可能会有一个注释,该注释表示在编译时调用的类,并允许您修改或注入代码. Dart注释也可以这样工作吗?

For example with Java you might have an annotation that represents a class that is invoked at compile time and let you modify or inject code. Do Dart annotations work like this as well?

在理解Dart生态系统的这一领域方面,我做了一些(进一步的)挖掘.我要添加一些注释,因为注释可以提供强大的功能,并提供有关如何使用注释的透明注释.

I have done some (further) digging on understanding this area of the Dart ecosystem. I'm adding some notes because annotation can be a powerful with transparent commentary on how to use it.

查看Dart的一些实际注释后,Dart注释会记录"符号"(标签或 metadata 标签).问题在于如何在Dart中使用注释.

After looking at some actual annotation from Dart, Dart annotations record "a notation" (a label or metadata tags). The question is about how to uses annotations within Dart.

基于对代码的了解,我目前的理解是它们是类对象上的标记.注释似乎是高度非结构化因为注释可以简单地声明,但是没有使用或识别标签的结构(又名 annotation ).

My current understanding, based on looking at bits of code, is that they are markers on class objects. It looks like annotations are highly-unstructured since while an annotation can be declared simply, there's no structure to use or recognise a label (aka annotation).

注释步骤

  1. 标识要标记的属性或操作.
  2. 需要编写代码以使用或'工作'您的注释.查看类似 观察 .
  3. 您可以实现和测试LOAD-time代码,以查找和处理标签.我看不到注册注释和提供处理程序的基础架构.
    • 这是通过库中的main()方法完成的.
  1. Identify the property or action you want to label.
  2. Need to write code to use or 'work' your annotation. Look at something like Observe as an example.
  3. You can implement and test LOAD-time code to look-for and process your labels. I don't see an infrastructure to register an annotation and provide handlers for example.
    • This is done via the main() method in your library.

至少我认为这是这样的.

At least I think that's how it works. There's not really a lot of information in the Dart language specification on this area.

观察和检查也提出了一些一般性问题.我留下了各种示例的阅读清单,以帮助其他人加入探索.

Observation and inspection raised a few general questions as well. I've left a reading list of sorts and examples, to assist others in joining the exploration.

读数:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆