<example> </ example> XML注释标记:如何查看?

Art*_*kyi 13 .net c# intellisense objectbrowser visual-studio-2012

我使用Microsoft Visual Studio 2012.当我将代码示例放入C#classes/methods的XML注释中时,我想知道:引用我的程序集的用户将如何看到该代码示例?

我试图引用自己的程序集,我找到的唯一方法是:查看assembly.xml文件.我可以解决Visual Studio或其他任何东西来查看这些代码示例吗?

以下是我对评论的评价:

/// <summary>
/// This is my method example
/// </summary>
/// <example>
/// <code>
/// // Here is my code example. Call my method like this:
/// const int a = 10;
/// MethodExample(a);
/// </code>
/// </example>
public static void MethodExample(int parameter)
{
}
Run Code Online (Sandbox Code Playgroud)

这是我在intellisense中得到的:

在此输入图像描述

这是我在对象浏览器中得到的:

在此输入图像描述

这是我在assembly.xml文件中得到的:

在此输入图像描述

我想得到的内容:请参阅对象浏览器和智能感知中的代码示例.

Pas*_*nse 11

许多 XML 注释标记仅作为其他标记的子元素出现在 IntelliSense 中。这些标记称为 ChildCompletionList 标记,包括:c、code、example、list、listheader、para、paramref、see 和 see Also。

/// <summary>
/// MethodExample the function that does it all...
/// <example>
/// <code>
/// <para/>// Here is my code example. Call my method like this:
/// <para/>const int a = 10;
/// <para/>MethodExample(a);
/// </code>
/// </example>
/// </summary>
Run Code Online (Sandbox Code Playgroud)

  • 在 VS 2012 中,如果我使用 &lt;summary&gt;&lt;example&gt;&lt;code&gt;&lt;/code&gt;&lt;/example&gt;&lt;/summary&gt; ,则代码元素中的文本在智能感知和对象浏览器中显示为未格式化。十分难看。 (4认同)
  • 对于最终用户来说,如果我只是将代码放在没有 &lt;example&gt; 和 &lt;code&gt; 标签的摘要中,这之间有什么区别? (2认同)
  • @CJBS,“Visual Studio 内的 IntelliSense 使用 &lt;summary&gt; 标记来显示有关类型或成员的附加信息。” 因此,如果您希望在智能感知中显示示例使用信息,则需要将该信息包含在 &lt;summary&gt; 块中。https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/xmldoc/how-to-use-the-xml-documentation-features (2认同)