语法
<summary>description</summary>
参数
-
description
对象的摘要。
备注
<summary> 标记应当用于描述类型或类型成员。 使用 <remarks> 可针对某个类型说明添加补充信息。 使用 cref 属性可启用文档工具(如 DocFX 和 Sandcastle)来创建指向代码元素的文档页的内部超链接。
<summary> 标记的文本是唯一有关 IntelliSense 中的类型的信息源,它也显示在对象浏览器窗口中。
使用 -doc 进行编译以便将文档注释处理到文件中。 若要基于编译器生成的文件创建最终文档,可以创建一个自定义工具,也可以使用 DocFX 或 Sandcastle 等工具。
示例
// compile with: -doc:DocFileName.xml
/// text for class TestClass
public class TestClass
{
/// <summary>DoWork is a method in the TestClass class.
/// <para>Here's how you could make a second paragraph in a description. <see cref="System.Console.WriteLine(System.String)"/> for information about output statements.</para>
/// <seealso cref="TestClass.Main"/>
/// </summary>
public static void DoWork(int Int1)
{
}
/// text for Main
static void Main()
{
}
}
前面的示例生成下面的 XML 文件。
<?xml version="1.0"?>
<doc>
<assembly>
<name>YourNamespace</name>
</assembly>
<members>
<member name="T:TestClass">
text for class TestClass
</member>
<member name="M:TestClass.DoWork(System.Int32)">
<summary>DoWork is a method in the TestClass class.
<para>Here's how you could make a second paragraph in a description. <see cref="M:System.Console.WriteLine(System.String)"/> for information about output statements.</para>
<seealso cref="M:TestClass.Main"/>
</summary>
</member>
<member name="M:TestClass.Main">
text for Main
</member>
</members>
</doc>
示例
下面的示例演示如何对泛型类型进行 cref
引用。
// compile with: -doc:DocFileName.xml
// the following cref shows how to specify the reference, such that,
// the compiler will resolve the reference
/// <summary cref="C{T}">
/// </summary>
class A { }
// the following cref shows another way to specify the reference,
// such that, the compiler will resolve the reference
// <summary cref="C < T >">
// the following cref shows how to hard-code the reference
/// <summary cref="T:C`1">
/// </summary>
class B { }
/// <summary cref="A">
/// </summary>
/// <typeparam name="T"></typeparam>
class C<T> { }
class Program
{
static void Main() { }
}
前面的示例生成下面的 XML 文件。
<?xml version="1.0"?>
<doc>
<assembly>
<name>CRefTest</name>
</assembly>
<members>
<member name="T:A">
<summary cref="T:C`1">
</summary>
</member>
<member name="T:B">
<summary cref="T:C`1">
</summary>
</member>
<member name="T:C`1">
<summary cref="T:A">
</summary>
<typeparam name="T"></typeparam>
</member>
</members>
</doc>