gpt4 book ai didi

dart - 如何在 dartdoc 中引用构造函数和运算符?

转载 作者:行者123 更新时间:2023-12-03 02:51:16 24 4
gpt4 key购买 nike

Dart Language Tour涵盖文档注释,并说:

Inside a documentation comment, the Dart compiler ignores all text unless it is enclosed in brackets. Using brackets, you can refer to classes, methods, fields, top-level variables, functions, and parameters. The names in brackets are resolved in the lexical scope of the documented program element.



我可能希望能够引用作用域中的任何内容,但是我在弄清楚如何引用命名和未命名构造函数以及运算符时遇到了麻烦。

我创建了一个带有文档注释的测试库:
/// # Thingy
///
/// Blah [GLOBAL] blah [function] blah [Thingy] blah [Thingy.property] blah
/// [Thingy.virtualProperty] blah [Thingy.named] blah [Thingy.method]
/// blah [Thingy.operator+].
/// Try these: [Thingy.named()] blah [Thingy.()] blah [Thingy()].

library Thingy;

const int GLOBAL = 0;

void function(int arg) {}

/// A class.
///
/// Blah [GLOBAL] blah [function] blah [Thingy] blah [property] blah
/// [virtualProperty] blah [named] blah [method] blah [operator+].
/// Try these: [Thingy.named()] blah [Thingy.()] blah [Thingy()].
class Thingy {

int property;

int get virtualProperty => 0;
set virtualProperty(int arg) {}

Thingy(int arg) {}
Thingy.named(int arg) {}

/// A method.
///
/// Blah [GLOBAL] blah [function] blah [Thingy] blah [property] blah
/// [virtualProperty] blah [named] blah [method] blah [operator+] blah
/// [arg].
/// Try these: [Thingy.named()] blah [Thingy.()] blah [Thingy()].
void method(int arg) {}

Thingy operator+(int arg) => null;
}

Dartdoc 生成的库、类和方法文档如下所示:

Blah GLOBAL blah function blah Thingy blah property blah virtualProperty blah named blah method blah operator+ ...

Try these: Thingy.named blah Thingy.() blah Thingy().



(不是实际的 Dartdoc 输出 - 只是它的样子。用于模拟链接的 Dart 语言教程 URL。)

大多数引用都有效,但我如何引用构造函数和运算符?

最佳答案

构造函数指的是 new

/// [new MyClass] 
/// [new MyClass.someNamedConstructor]

我还没有找到引用运算符的方法
/// [operator ==] or [==] seem not to work

我创建了 https://github.com/dart-lang/dartdoc/issues/1087

关于dart - 如何在 dartdoc 中引用构造函数和运算符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34907717/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com