使用 C# 的 XML 注释 cref 属性和 params 语法

发布于 2024-07-16 16:38:15 字数 196 浏览 5 评论 0原文

在 C# 中,我尝试使用引用包含 params 关键字的方法签名。 我知道这会将参数列表转换为数组,但我什至不知道如何在 CREF 属性中引用数组。 我在搜索中什么也没找到,而且我认识的人也不知道。 编译器因方括号而窒息。 我尝试过各种不同的组合,使用花括号,使用 Array 类,但没有任何效果。 有人知道这个吗?

In C#, I am trying to use <see cref="blah"/> to reference a method signature that contains the params keyword. I know this converts the parameter list to an array, but I can't even figure out how to refer to an array in a CREF attribute. I am finding nothing in my searches and no one I know has any idea, either. The compiler is choking on the square brackets. I've tried all kinds of different combinations, using curly braces, using the Array class, but nothing is working. Does anyone know this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

幸福丶如此 2024-07-23 16:38:15

根据 B.3.1 ID string format 文章,引用数组是用[方括号](带有可选的lowerbound:size说明符)完成的,但如果你只想引用某种类型的数组(甚至是对象数组),你可以不只是写

而是需要指定您正在使用 T: 前缀进行类型引用,例如

这似乎不适用于引用方法的特定重载,例如

According to the B.3.1 ID string format article, referencing an array is done with [square brackets] (with optional lowerbound:size specifiers) but if you just want to refer to an array of a certain type (or even an Object array), you can't just write

<see cref="Object[]"/>

instead you need to specify you're making a type reference with the T: prefix, like

<see cref="T:Object[]"/>

This does not seem to apply when referencing a specific overload of a method, such as

<seealso cref="String.Join(String, String[])"/>

倒带 2024-07-23 16:38:15

ECMA 334 标准 PDF 附件 E 包含对 XML 文档注释的全面概述。 您可以在以下位置下载该标准:

http://www.ecma-international .org/publications/standards/Ecma-334.htm

具体来说,您需要从第 496 页开始的 E.3.1 部分。MSDN

上也有类似的内容(尽管 MSDN 似乎在该主题上的导航很糟糕,很难找到其他部分):

http:// /msdn.microsoft.com/en-us/library/aa664787(VS.71).aspx

相当于 E.3.1:

http://msdn.microsoft.com/en-us/library/aa664807(VS.71).aspx

您还可以发现 Mono 的文档很有用:

http:// www.go-mono.com/docs/index.aspx?tlink=29@man%3amdoc(5)

具体来说,“CREF FORMAT”部分涵盖了 ID 字符串约定。

更新 2018/05/23

上述 ECMA-334 标准 PDF 的 URL 链接到该标准的最新版本。 2009年,这是该标准的第四版。 然而,截至 2017 年 12 月,第 5 版已生效,第 4 版中的 E.3.1 节变成了第 5 版中的 D.4.2 节。

ECMA-334 标准的早期版本可从以下页面下载: https://www.ecma-international.org/publications/standards/Ecma-334-arch.htm

更新 2023/11/20

ECMA-334 标准链接现已https://ecma-international.org/publications-and-standards/standards/ecma- 334/

The ECMA 334 Standard PDF, Annex E contains a decent overview of XML Documentation comments. You can download the standard at:

http://www.ecma-international.org/publications/standards/Ecma-334.htm

Specifically, you'll want section E.3.1, starting on page 496.

Similar content is also at MSDN (though MSDN seems to have terrible navigation on this topic, making it difficult to find the other sections):

http://msdn.microsoft.com/en-us/library/aa664787(VS.71).aspx

The equivalent to E.3.1:

http://msdn.microsoft.com/en-us/library/aa664807(VS.71).aspx

You may also find Mono's documentation useful:

http://www.go-mono.com/docs/index.aspx?tlink=29@man%3amdoc(5)

Specfically, the "CREF FORMAT" section covers the ID string conventions.

Update 2018/05/23

The URL for the ECMA-334 standard PDF above links to the latest edition of the standard. In 2009, that was the 4th edition of the standard. However, as of December 2017, the 5th edition is current, and section E.3.1 from the 4th edition became section D.4.2 in the 5th edition.

The previous versions of the ECMA-334 standard are available for download from the following page: https://www.ecma-international.org/publications/standards/Ecma-334-arch.htm

Update 2023/11/20

Link to ECMA-334 standard is now https://ecma-international.org/publications-and-standards/standards/ecma-334/

So要识趣 2024-07-23 16:38:15

您只需省略 param 关键字并输入如下所示的类型:

/// <summary>
/// <see cref="Method(string[])"/>
/// </summary>
public static void Main()
{
    Method("String1", "String2");
}

public static void Method(params string[] values)
{
    foreach (string value in values)
    {
        Console.WriteLine(value);
    }
}

You just leave out the param keyword and put in the type like this:

/// <summary>
/// <see cref="Method(string[])"/>
/// </summary>
public static void Main()
{
    Method("String1", "String2");
}

public static void Method(params string[] values)
{
    foreach (string value in values)
    {
        Console.WriteLine(value);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文