是否有用于评论C#代码的标准(如phpdoc或python的docstring)?

Mar*_*iek 25 c# comments

是否有标准约定(如phpdoc或python的docstring)用于注释C#代码,以便可以从源代码自动生成类文档?

For*_*lon 32

您可以使用XML样式注释,并使用工具将这些注释提取到API文档中.

以下是评论样式的示例:

/// <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)
Run Code Online (Sandbox Code Playgroud)

一些便于此的项目是:

GhostDoc,它提供一个快捷键来自动为类或方法生成注释. Sandcastle,从XML注释生成MSDN样式文档.

  • 有关 Sandcastle 的更多信息,请参阅 http://stackoverflow.com/questions/319632/docproject-vs-sandcastle-help-file-builder-gui。 (2认同)