文档注释是为了方便自己和他人更好地理解代码所实现的功能。下面记录了一些常用的文档注释标记:

<C>

用法: <c>text</c>

将说明中的文本标记为代码。例如:

/// <summary>
/// Validates the user.
/// </summary>
/// <param name="username">The username.</param>
/// <param name="password">The password.</param>
/// <returns>
/// <c>true</c>, if username and password are equal.
/// </returns>
public bool ValidateUser(string username, string password)
{
var userId = GetUserIdIfValid(username, password);
return userId.HasValue && userId.Value != Guid.Empty;
}

<code>

用法: <code>content</code>

将多行文本标记为代码。

<see>

用法: <see cref="member"/>

用于从文本中指定链接。例如:

/// <summary>
/// Initializes a new instance of the <see cref="DefaultAuthenticationService" /> class.
/// </summary>
/// <param name="repository">The repository.</param>
public DefaultAuthenticationService(IRepository repository)
{
this.repository = repository;
}

<example>

用法: <example>description</example>

用于指定使用方法或其他库成员的示例。例如:

/// <summary>
/// The GetZero method.
/// </summary>
/// <example>
/// This sample shows how to call the <see cref="GetZero"/> method.
/// <code>
/// class TestClass
/// {
/// static int Main()
/// {
/// return GetZero();
/// }
/// }
/// </code>
/// </example>
public static int GetZero()
{
return ;
}

<param>

用法: <param name="name">description</param>

用于描述方法的一个参数。

<paramref>

用法: <paramref name="name"/>

用于引用某个参数。例如:

/// <summary>
/// Gets a collection of membership users where the user name contains the specified user name to match.
/// </summary>
/// <param name="usernameToMatch">The user name to search for.</param>
/// <param name="pageIndex">The index of the page of results to return. <paramref name="pageIndex" /> is zero-based.</param>
/// <param name="pageSize">The size of the page of results to return.</param>
/// <param name="totalRecords">The total number of matched users.</param>
/// <returns>
/// A <see cref="T:System.Web.Security.MembershipUserCollection" /> collection that contains a page of <paramref name="pageSize" /><see cref="T:System.Web.Security.MembershipUser" /> objects beginning at the page specified by <paramref name="pageIndex" />.
/// </returns>
public IList<User> FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
{
return GetUsers(pageIndex, pageSize, out totalRecords, u => u.UserName.Contains(usernameToMatch));
}

<returns>

用法: <returns>description</returns>

用于描述返回值。

<summary>

用法: <summary>description</summary>

用于描述类型或类型成员。

<typeparam>

用法: <typeparam name="name">description</typeparam>

用于在泛型类型或方法声明的注释中描述类型参数。例如:

/// <summary>
/// Creates a new array of arbitrary type <typeparamref name="T"/>
/// </summary>
/// <typeparam name="T">The element type of the array</typeparam>
/// <param name="n"></param>
/// <returns></returns>
public static T[] mkArray<T>(int n)
{
return new T[n];
}

<typeparamref>

用法: <typeparamref name="name"/>

用于引用泛型参数。

<value> 

用法: <value>property-description</value>

用于描述属性所代表的值。 请注意,当在 Visual Studio .NET 开发环境中通过代码向导添加属性时,它将会为新属性添加 <summary>标记。 然后,应该手动添加 <value> 标记以描述该属性所表示的值。例如:

/// <summary>
/// Gets or sets the title.
/// </summary>
/// <value>
/// The title.
/// </value>
public virtual string Title { get; set; }

<exception>

用法: <exception cref="member">description</exception>

用于说明可被引发的异常。例如:

/// <summary>
/// Gets the and validates property.
/// </summary>
/// <param name="propertyName">Name of the property.</param>
/// <returns>Reflection property info object</returns>
/// <exception cref="System.InvalidOperationException">Model has no such property</exception>
private System.Reflection.PropertyInfo GetAndValidateProperty(string propertyName)
{
var property = modelType.GetProperty(propertyName); if (property == null)
{
property = modelType.GetProperty(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(propertyName)); if (property == null)
{
throw new InvalidOperationException(string.Format("Property {0} doesn't exist in object {1}", propertyName, modelType));
}
} return property;
}

参考文档

  1. https://msdn.microsoft.com/zh-cn/library/te6h7cxs%28v=vs.110%29.aspx
  2. https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/language-specification/documentation-comments

C#中的XML文档注释-推荐的文档注释标记的更多相关文章

  1. 使用.NET中的XML注释(二) -- 创建帮助文档入门篇

    一.摘要 在本系列的第一篇文章介绍了.NET中XML注释的用途, 本篇文章将讲解如何使用XML注释生成与MSDN一样的帮助文件.主要介绍NDoc的继承者:SandCastle. 二.背景 要生成帮助文 ...

  2. 突发奇想之:源码及文档,文档包括源码---xml格式的源码,文档源码合并;注释文档化,文档代码化;

    目前源码和文档一般都是分开的,我在想为什么 源码不就是最好的文档么? 但是一般源码都是文本text的,格式化需要人为统一规范,所以源码中的文档在现实中不是那么的易于实践. 而且 源码 不能包括图片.附 ...

  3. DOM和SAX是应用中操纵XML文档的差别

    查看原文:http://www.ibloger.net/article/205.html DOM和SAX是应用中操纵XML文档的两种主要API.它们分别解释例如以下:          DOM.即Do ...

  4. 使用.NET中的XML注释(一) -- XML注释标签讲解

    一.摘要 .Net允许开发人员在源代码中插入XML注释,这在多人协作开发的时候显得特别有用. C#解析器可以把代码文件中的这些XML标记提取出来,并作进一步的处理为外部文档. 这篇文章将展示如何使用这 ...

  5. .Net魔法堂:提取注释生成API文档

    一.前言 在多人协作的项目中,除了良好的代码规范外,完整的API文档也相当重要.通过文档我们快速了解系统各模块的实际接口,及其使用场景.使用示例,一定程度上降低沟通成本,和减少后期维护中知识遗失等风险 ...

  6. .net 提取注释生成API文档 帮助文档

    提取注释生成API文档   一.前言 在多人协作的项目中,除了良好的代码规范外,完整的API文档也相当重要.通过文档我们快速了解系统各模块的实际接口,及其使用场景.使用示例,一定程度上降低沟通成本,和 ...

  7. xml基础之二(XML结构【2】)DTD文档模版

    xml基础之二(XML结构[2])DTD文档模版 xml 模板 文档结构  我们知道XML主要用于数据的存储和传输,所以无论是自定义还是外部引用DTD模板文档,都是为了突出数据的存储规范.DTD(文档 ...

  8. 注释生成Api文档

    1.开发背景 最近一直在写dubbo接口,以前总是用word文档写接口描述然后发给别人.现在太多了,而且跟别人对接联调的人家急着用,根本没时间去写word文档.那就想想怎么用doc文档注释自动生成接口 ...

  9. 使用sphinx快速为你python注释生成API文档

    sphinx简介sphinx是一种基于Python的文档工具,它可以令人轻松的撰写出清晰且优美的文档,由Georg Brandl在BSD许可证下开发.新版的Python3文档就是由sphinx生成的, ...

随机推荐

  1. 关系逻辑运算符---------&&和||

    1.&&符号 常规用法没什么好说的,我们来说说其不同于java的特殊之处 (1)&&符号究竟返回什么 我们知道,0,null,defined,null,NaN等都可以转 ...

  2. ntp服务器同步时间详细配置

    部署NTP服务器进行时间同步   NTP服务端:linl_S    IP:10.0.0.15 NTP客户端:lin_C    IP:10.0.0.16 NTP服务概述 1.原理 NTP(Network ...

  3. bzoj 3522: Hotel dfs

    题目大意 在无边权树上求三个点,使两两点的距离等.求方案数\((n\leq 5000)\) 题解 我们知道三个点在树上的关系只有两种 三点共链 三点不共连 (这不是废话吗) 我们发现三点共链肯定不满足 ...

  4. Http客户端跳转和服务器端跳转的区别

    服务器端跳转:      服务器转发全程是没有客户端参与的,都在web container容器内部进行,没有任何服务器和客户端的通信,实际就是服务器内部的跳转. 这次forward, 服务器没有构建H ...

  5. Spring读取加密属性文件处理--待整理

    引言:Spring框架俨然已经是目前Java WEB项目开发的一个宠儿,更有人将Spring, Struts,和Hibernage称之为Java WEB项目开发的3件利器.Spring的依赖.注入.A ...

  6. UnrealScript常用函数汇总

    转自:http://www.unrealchina.org/forum.php?mod=viewthread&tid=672&extra=page%3D1 foreach [用来遍历游 ...

  7. day1 java基础回顾- Properties类与配置文件

    Properties配置文件说明 Properties类对应.properties文件.文件内容是键值对,键值对之间使用"="或空格隔开.开头是"#"的表示注释 ...

  8. 1.14不使用回车键来读取n个字符

    read是一个重要的bash命令,它用于从键盘或标准输入中读取文本.可以使用read以交互的形式读取来自用户的输入,不过read能做的远不止这些.很多编程语言的输入库都是从键盘读取输入,且只有回车键按 ...

  9. linux命令之env和export

    1.查看环境变量: env查看所有的环境变量: 使用echo命令查看单个环境变量.例如: echo $PATH 使用set查看所有本地定义的环境变量. unset可以删除指定的环境变量. 2.常用环境 ...

  10. 删除ue4中c++类

    http://gad.qq.com/program/translateview/7190281 删除一个C++类 该方法是从UE4的answerhub上摘选的.本教程介绍了从项目中删除一个C++类所需 ...