C# 如何在 IntelliSense 中为 Visual Studio 中的函数添加注释?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/529677/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 06:55:48  来源:igfitidea点击:

How to have comments in IntelliSense for function in Visual Studio?

c#vb.netvisual-studiovisual-studio-2008xml-comments

提问by Ali

In Visual Studio and C#, when using a built in function such as ToString(), IntelliSense shows a yellow box explaining what it does.

在 Visual Studio 和 C# 中,当使用内置函数(如 ToString())时,IntelliSense 会显示一个黄色框,说明它的作用。

alt textalt text

替代文字替代文字

How can I have that for functions and properties I write?

我怎么能有我写的函数和属性?

采纳答案by Solmead

To generate an area where you can specify a description for the function and each parameter for the function, type the following on the line before your function and hit Enter:

要生成一个区域,您可以在其中指定函数的描述和函数的每个参数,请在函数之前的行中键入以下内容并点击Enter

  • C#:///

  • VB:'''

  • C#:///

  • VB:'''

See Recommended Tags for Documentation Comments (C# Programming Guide)for more info on the structured content you can include in these comments.

有关可以包含在这些注释中的结构化内容的更多信息,请参阅文档注释的推荐标签(C# 编程指南)

回答by Michael Walts

Do XML commenting , like this

做 XML 注释,像这样

/// <summary>
/// This does something that is awesome
/// </summary>
public void doesSomethingAwesome() {}

回答by Ed S.

Solmead has the correct answer. For more info you can look at XML Comments.

索尔米德有正确的答案。有关更多信息,您可以查看XML 注释

回答by DevelopingChris

use /// to begin each line of the comment and have the comment contain the appropriate xmlfor the meta data reader.

使用 /// 开始注释的每一行,并使注释包含元数据阅读器的适当 xml

///<summary>
/// this method says hello
///</summary>
public void SayHello();

Although personally, I believe that these comments are usually misguided, unless you are developing classes where the code cannot be read by its consumers.

虽然就我个人而言,我认为这些评论通常是误导性的,除非您正在开发其消费者无法读取代码的类。

回答by Mark Rogers

Also the visual studio add-in ghost doc will attempt to create and fill-in the header comments from your function name.

此外,visual studio 插件 ghost doc 将尝试根据您的函数名称创建和填充标题注释。

回答by Tomas Aschan

What you need is xml comments- basically, they follow this syntax (as vaguely described by Solmead):

您需要的是xml 注释- 基本上,它们遵循以下语法(如 Solmead 模糊描述):

C#

C#

///<summary>
///This is a description of my function.
///</summary>
string myFunction() {
     return "blah";
}

VB

VB

'''<summary>
'''This is a description of my function.
'''</summary>
Function myFunction() As String
    Return "blah"
End Function

回答by Igal Tabachnik

Those are called XML Comments. They have been a part of Visual Studio since forever.

这些被称为XML 注释。它们一直是 Visual Studio 的一部分。

You can make your documentation process easier by using GhostDoc, a free add-in for Visual Studio which generates XML-doc comments for you. Just place your caret on the method/property you want to document, and press Ctrl-Shift-D.

您可以使用GhostDoc 简化您的文档过程,GhostDoc是 Visual Studio 的免费插件,可为您生成 XML 文档注释。只需将插入符号放在要记录的方法/属性上,然后按 Ctrl-Shift-D。

Here's an example from one of my posts.

是我的一篇帖子中的一个例子。

Hope that helps :)

希望有帮助:)

回答by user1180781

read http://msdn.microsoft.com/en-us/library/3260k4x7.aspxJust specifying the comments will not show the help comments in intellisense.

阅读http://msdn.microsoft.com/en-us/library/3260k4x7.aspx仅指定注释不会在智能感知中显示帮助注释。

回答by Semperfi89

In CSharp, If you create the method/function outline with it's Parms, then when you add the three forward slashes it will auto generate the summary and parms section.

在 CSharp 中,如果您使用 Parms 创建方法/函数大纲,那么当您添加三个正斜杠时,它将自动生成摘要和参数部分。

So I put in:

所以我输入:

public string myMethod(string sImput1, int iInput2)
{
}

I then put the three /// before it and Visual Studio's gave me this:

然后我把三个 /// 放在它前面,Visual Studio 给了我这个:

/// <summary>
/// 
/// </summary>
/// <param name="sImput1"></param>
/// <param name="iInput2"></param>
/// <returns></returns>
public string myMethod(string sImput1, int iInput2)
{
}

回答by Max

<c>text</c>- The text you would like to indicate as code.
The <c> tag gives you a way to indicate that text within a description should be marked as code. Use <code> to indicate multiple lines as code.

<c>text</c>- 您希望作为代码指示的文本。
< c> 标记为您提供了一种方法来指示应将描述中的文本标记为代码。使用 < code> 将多行表示为代码。

<code>content</code>- The text you want marked as code.
The <code> tag gives you a way to indicate multiple lines as code. Use <c> to indicate that text within a description should be marked as code.

<code>content</code>- 要标记为代码的文本。
< code> 标签为您提供了一种将多行指示为代码的方法。使用 < c> 表示应将描述中的文本标记为代码。

<example>description</example>- A description of the code sample.
The <example> tag lets you specify an example of how to use a method or other library member. This commonly involves using the <code> tag.

<example>description</example>- 代码示例的描述。
< example> 标签允许您指定如何使用方法或其他库成员的示例。这通常涉及使用 < code> 标签。

<exception cref="member">description</exception>- A description of the exception.
The <exception> tag lets you specify which exceptions can be thrown. This tag can be applied to definitions for methods, properties, events, and indexers.

<exception cref="member">description</exception>- 异常的描述。
< exception> 标签允许您指定可以抛出哪些异常。此标记可应用于方法、属性、事件和索引器的定义。

<include file='filename' path='tagpath[@name="id"]' />
The <include> tag lets you refer to comments in another file that describe the types and members in your source code. This is an alternative to placing documentation comments directly in your source code file. By putting the documentation in a separate file, you can apply source control to the documentation separately from the source code. One person can have the source code file checked out and someone else can have the documentation file checked out. The <include> tag uses the XML XPath syntax. Refer to XPath documentation for ways to customize your <include> use.

<include file='filename' path='tagpath[@name="id"]' />
< include> 标签允许您引用另一个文件中描述源代码中的类型和成员的注释。这是直接在源代码文件中放置文档注释的替代方法。通过将文档放在单独的文件中,您可以将源代码控制应用于与源代码分开的文档。一个人可以签出源代码文件,其他人可以签出文档文件。< include> 标记使用 XML XPath 语法。有关自定义 < include> 使用的方法,请参阅 XPath 文档。

<list type="bullet" | "number" | "table">
    <listheader>
        <term>term</term>
        <description>description</description>
    </listheader>
    <item>
        <term>term</term>
        <description>description</description>
    </item>
</list>

The <listheader> block is used to define the heading row of either a table or definition list. When defining a table, you only need to supply an entry for term in the heading. Each item in the list is specified with an <item> block. When creating a definition list, you will need to specify both term and description. However, for a table, bulleted list, or numbered list, you only need to supply an entry for description. A list or table can have as many <item> blocks as needed.

< listheader> 块用于定义表或定义列表的标题行。定义表格时,您只需要在标题中为术语提供一个条目。列表中的每一项都用 < item> 块指定。创建定义列表时,您需要指定术语和描述。但是,对于表格、项目符号列表或编号列表,您只需提供一个条目进行说明。列表或表格可以根据需要具有任意数量的 < item> 块。

<para>content</para>
The <para> tag is for use inside a tag, such as <summary>, <remarks>, or <returns>, and lets you add structure to the text.

<para>content</para>
< para> 标签用于在标签内使用,例如 < summary>、< comments> 或 < returns>,并允许您向文本添加结构。

<param name="name">description</param>
The <param> tag should be used in the comment for a method declaration to describe one of the parameters for the method. To document multiple parameters, use multiple <param> tags.
The text for the <param> tag will be displayed in IntelliSense, the Object Browser, and in the Code Comment Web Report.

<param name="name">description</param>
< param> 标签应该用在方法声明的注释中,以描述方法的参数之一。要记录多个参数,请使用多个 < param> 标签。
< param> 标记的文本将显示在 IntelliSense、对象浏览器和代码注释 Web 报告中。

<paramref name="name"/>
The <paramref> tag gives you a way to indicate that a word in the code comments, for example in a <summary> or <remarks> block refers to a parameter. The XML file can be processed to format this word in some distinct way, such as with a bold or italic font.

<paramref name="name"/>
该< paramref>标记为您提供了一种方式来表明代码中的注释在<一个字,例如摘要>或<讲话>块是指一个参数。可以对 XML 文件进行处理,以某种不同的方式来格式化这个词,例如使用粗体或斜体。

<permission cref="member">description</permission>
The <permission> tag lets you document the access of a member. The PermissionSet class lets you specify access to a member.

< permission cref="member">description</permission>
< permission> 标签让您记录成员的访问权限。PermissionSet 类允许您指定对成员的访问权限。

<remarks>description</remarks>
The <remarks> tag is used to add information about a type, supplementing the information specified with <summary>. This information is displayed in the Object Browser.

<remarks>description</remarks>
< remarks>标签用于添加一个类型的信息,补充< summary>指定的信息。此信息显示在对象浏览器中。

<returns>description</returns>
The <returns> tag should be used in the comment for a method declaration to describe the return value.

<returns>description</returns>
< returns> 标签应该用在方法声明的注释中来描述返回值。

<see cref="member"/>
The <see> tag lets you specify a link from within text. Use <seealso> to indicate that text should be placed in a See Also section. Use the cref Attribute to create internal hyperlinks to documentation pages for code elements.

<see cref="member"/>
< see> 标签允许您从文本中指定链接。使用 < seealso> 指示应将文本放置在 See Also 部分中。使用 cref 属性创建指向代码元素文档页面的内部超链接。

<seealso cref="member"/>
The <seealso> tag lets you specify the text that you might want to appear in a See Also section. Use <see> to specify a link from within text.

<seealso cref="member"/>
< seealso> 标签可让您指定可能希望出现在“另请参阅”部分中的文本。使用 < see> 从文本中指定链接。

<summary>description</summary>
The <summary> tag should be used to describe a type or a type member. Use <remarks> to add supplemental information to a type description. Use the cref Attribute to enable documentation tools such as Sandcastle to create internal hyperlinks to documentation pages for code elements. The text for the <summary> tag is the only source of information about the type in IntelliSense, and is also displayed in the Object Browser.

<summary>description</summary>
< summary> 标签应该用于描述一个类型或一个类型成员。使用 <备注> 向类型描述添加补充信息。使用 cref 属性启用 Sandcastle 等文档工具,以创建指向代码元素文档页面的内部超链接。< summary> 标记的文本是有关 IntelliSense 中类型信息的唯一来源,也显示在对象浏览器中。

<typeparam name="name">description</typeparam>
The <typeparam> tag should be used in the comment for a generic type or method declaration to describe a type parameter. Add a tag for each type parameter of the generic type or method. The text for the <typeparam> tag will be displayed in IntelliSense, the Object Browser code comment web report.

<typeparam name="name">description</typeparam>
< typeparam> 标签应该用在泛型类型或方法声明的注释中来描述类型参数。为泛型类型或方法的每个类型参数添加一个标签。< typeparam> 标记的文本将显示在 IntelliSense(对象浏览器代码注释 Web 报告)中。

<typeparamref name="name"/>
Use this tag to enable consumers of the documentation file to format the word in some distinct way, for example in italics.

<typeparamref name="name"/>
使用此标记使文档文件的使用者能够以某种不同的方式格式化单词,例如斜体。

<value>property-description</value>
The <value> tag lets you describe the value that a property represents. Note that when you add a property via code wizard in the Visual Studio .NET development environment, it will add a <summary> tag for the new property. You should then manually add a <value> tag to describe the value that the property represents.

<value>property-description</value>
< value> 标签让你描述一个属性代表的值。请注意,当您在 Visual Studio .NET 开发环境中通过代码向导添加属性时,它将为新属性添加一个 < summary> 标记。然后,您应该手动添加一个 < value> 标记来描述该属性所代表的值。