C#中的XML文档注释-推荐的文档注释标记
文档注释是为了方便自己和他人更好地理解代码所实现的功能。下面记录了一些常用的文档注释标记:
<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;
}
参考文档
- https://msdn.microsoft.com/zh-cn/library/te6h7cxs%28v=vs.110%29.aspx
- https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/language-specification/documentation-comments
C#中的XML文档注释-推荐的文档注释标记的更多相关文章
- 使用.NET中的XML注释(二) -- 创建帮助文档入门篇
一.摘要 在本系列的第一篇文章介绍了.NET中XML注释的用途, 本篇文章将讲解如何使用XML注释生成与MSDN一样的帮助文件.主要介绍NDoc的继承者:SandCastle. 二.背景 要生成帮助文 ...
- 突发奇想之:源码及文档,文档包括源码---xml格式的源码,文档源码合并;注释文档化,文档代码化;
目前源码和文档一般都是分开的,我在想为什么 源码不就是最好的文档么? 但是一般源码都是文本text的,格式化需要人为统一规范,所以源码中的文档在现实中不是那么的易于实践. 而且 源码 不能包括图片.附 ...
- DOM和SAX是应用中操纵XML文档的差别
查看原文:http://www.ibloger.net/article/205.html DOM和SAX是应用中操纵XML文档的两种主要API.它们分别解释例如以下: DOM.即Do ...
- 使用.NET中的XML注释(一) -- XML注释标签讲解
一.摘要 .Net允许开发人员在源代码中插入XML注释,这在多人协作开发的时候显得特别有用. C#解析器可以把代码文件中的这些XML标记提取出来,并作进一步的处理为外部文档. 这篇文章将展示如何使用这 ...
- .Net魔法堂:提取注释生成API文档
一.前言 在多人协作的项目中,除了良好的代码规范外,完整的API文档也相当重要.通过文档我们快速了解系统各模块的实际接口,及其使用场景.使用示例,一定程度上降低沟通成本,和减少后期维护中知识遗失等风险 ...
- .net 提取注释生成API文档 帮助文档
提取注释生成API文档 一.前言 在多人协作的项目中,除了良好的代码规范外,完整的API文档也相当重要.通过文档我们快速了解系统各模块的实际接口,及其使用场景.使用示例,一定程度上降低沟通成本,和 ...
- xml基础之二(XML结构【2】)DTD文档模版
xml基础之二(XML结构[2])DTD文档模版 xml 模板 文档结构 我们知道XML主要用于数据的存储和传输,所以无论是自定义还是外部引用DTD模板文档,都是为了突出数据的存储规范.DTD(文档 ...
- 注释生成Api文档
1.开发背景 最近一直在写dubbo接口,以前总是用word文档写接口描述然后发给别人.现在太多了,而且跟别人对接联调的人家急着用,根本没时间去写word文档.那就想想怎么用doc文档注释自动生成接口 ...
- 使用sphinx快速为你python注释生成API文档
sphinx简介sphinx是一种基于Python的文档工具,它可以令人轻松的撰写出清晰且优美的文档,由Georg Brandl在BSD许可证下开发.新版的Python3文档就是由sphinx生成的, ...
随机推荐
- 1068 Bash游戏 V3
1068 Bash游戏 V3 题目来源: Ural 1180 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 收藏 关注 有一堆石子共有N个.A B两个人轮流拿 ...
- 洛谷P1020导弹拦截——LIS
题目:https://www.luogu.org/problemnew/show/P1020 主要是第二问,使用了dilworth定理:一个序列中最长不上升子序列的最大覆盖=最长上升子序列长度. di ...
- python json ajax django四星聚会
什么是json: JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.易于人阅读和编写.同时也易于机器解析和生成.它基于JavaScript Programm ...
- docker 学习(一)什么是Docker
项目中用到docker,就学习一下.第一篇是介绍. Sandboxie(沙箱):一个虚拟系统程序,允许你在沙盘环境中运行浏览器或其他程序,因此运行所产生的变化可以随后删除.它创造了一个类似沙盒的独立作 ...
- Pointer 指针
利用指针访问对象,指针指向一个对象,允许使用解引用符(操作符*)来访问对象 int ival = 42; int *p = &ival;//p存放变量ival的内存地址,p是指向变量ival的 ...
- MFC——4个基本类中的成员函数介绍
09121852 杜军 机械设计及理论 1. CMainFrame ActivateFrame使框架对用户可视并可用 CalcWindowRect每当主框架窗口的客户区尺寸发生变化或控制条的位置发生变 ...
- SetCapture到底是什么?
函数功能:该函数在属于当前线程的指定窗口里设置鼠标捕获.一旦窗口捕获了鼠标,所有鼠标输入都针对该窗口,无论光标是否在窗口的边界内.同一时刻只能有一个窗口捕获鼠标.如果鼠标光标在另一个线程创建的窗口上, ...
- 计总与排名SUM和RANK函数
准备一些数据: CREATE TABLE [dbo].[SalesPerformance]( ,) NOT NULL, ) NOT NULL, [OrderDate] [DATE] NULL, ,) ...
- DIV垂直水平居中
方法一:使用定位的方法 .parent { width: 300px; height: 200px; border: 1px solid red; position:relative; } .chil ...
- ue4 模拟tween
timeline的设置,注意timeLine可以使用外部的曲线,这个比较方便做各种曲线,timeline内部只适合打单个点