10

我知道这可能是一个基本问题,但我似乎无法在任何地方找到答案。

我有这样的课

Table<T>
{}

然后我有一些使用上述类的代码,我想评论一下我希望能够执行以下操作:

/// <summary>
/// blah blah blah Table<String>
/// </summary>

但是我不能在评论中使用尖括号,因为它认为它是一个标签,当帮助出现时,它只是有一个关于 no end tag for 的错误。

如何在 Visual Studio 的注释中显示泛型类。

4

4 回答 4

24

您需要使用 XML 实体(某种转义序列): < 对于 < 和 > 为 >。Intellisense 将正确显示 < as 和 >。

编辑:这是所有 XML 实体的备忘单列表:

&lt;   for <
&gt;   for >
&amp;  for &
&quot; for "
&apos; for '
于 2009-01-12T01:53:30.340 回答
2

尝试使用 < 而不是 <

于 2009-01-12T01:52:38.423 回答
1
于 2017-07-21T23:01:12.087 回答
0

If you place it in a cref element, you can instead use { and }.
That is, inside the summary, instead of Table<string>, you put <cref="Table{string}"/>

From XML Documentation Comments:

To refer to generic identifiers in code reference ... As a special case, the compiler parses the braces [in crefs] as angle brackets to make the documentation comment less cumbersome to author when referring to generic identifiers.

For more info about cref, see cref Attribute:

The cref attribute in an XML documentation tag means "code reference." It specifies that the inner text of the tag is a code element, such as a type, method, or property. Documentation tools like DocFX and Sandcastle use the cref attributes to automatically generate hyperlinks to the page where the type or member is documented.


NOTE: For convenience, I sometimes use {} instead of <> (in a summary comment) even if NOT part of a cref.

于 2019-03-22T21:05:28.760 回答