是否有用于注释 C# 代码的标准(如 phpdoc 或 python 的文档字符串)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34516/
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
Is there a standard (like phpdoc or python's docstring) for commenting C# code?
提问by Mark Biek
Is there a standard convention (like phpdoc or python's docstring) for commenting C# code so that class documentation can be automatically generated from the source code?
是否有用于注释 C# 代码的标准约定(如 phpdoc 或 python 的文档字符串),以便可以从源代码自动生成类文档?
采纳答案by Forgotten Semicolon
You can use XML style comments, and use tools to pull those comments out into API documentation.
您可以使用 XML 样式的注释,并使用工具将这些注释提取到 API 文档中。
Here is an example of the comment style:
以下是评论样式的示例:
/// <summary>
/// Authenticates a user based on a username and password.
/// </summary>
/// <param name="username">The username.</param>
/// <param name="password">The password.</param>
/// <returns>
/// True, if authentication is successful, otherwise False.
/// </returns>
/// <remarks>
/// For use with local systems
/// </remarks>
public override bool Authenticate(string username, string password)
Some items to facilitate this are:
一些有助于实现这一点的项目是:
GhostDoc, which give a single shortcut key to automatically generate comments for a class or method. Sandcastle, which generates MSDN style documentation from XML comments.
GhostDoc,它提供了一个快捷键来自动为类或方法生成注释。 Sandcastle,它从 XML 注释生成 MSDN 风格的文档。
回答by jason saldo
/// <summary>
///
/// </summary>
/// <param name="strFilePath"></param>
回答by hamishmcn
C# has built in documentation commandsHave fun!
C# 内置了文档命令玩得开心!
回答by Dan Herbert
Microsoft uses "XML Documentation Comments" which will give IDE intellisense descriptions and also allow you to auto-generate MSDN-style documentation using a tool such as Sandcastle if you turn on the generation of the XML file output.
Microsoft 使用“ XML 文档注释”,它将提供 IDE 智能感知描述,并且如果您打开 XML 文件输出的生成,还允许您使用 Sandcastle 等工具自动生成 MSDN 样式的文档。
To turn on the generation of the XML file for documentation, right click on a project in visual studio, click "Properties" and go to the "Build" tab. Towards the bottom you can specify a location for your XML comments output file.
要打开用于文档的 XML 文件的生成,请右键单击 Visual Studio 中的项目,单击“属性”并转到“构建”选项卡。在底部,您可以为 XML 注释输出文件指定一个位置。
回答by travis
The previous answers point out the XML syntax perfectly. I just wanted to throw in my recommendation for the free (and open-source) nDoc help library generatorthat parses all comments in a project.
前面的答案完美地指出了 XML 语法。我只是想推荐免费(和开源)nDoc 帮助库生成器,它可以解析项目中的所有注释。
回答by GameFreak
I was always told to use block comments opened with 2 or more asterisks do delimit documentation comments.
我总是被告知使用以 2 个或更多星号打开的块注释来分隔文档注释。
/**
Documentation goes here.
(flowerboxes optional)
*/