C#文档XML标记是我们在C#文档制作的时候必须要使用的,那么关于C#文档XML标记的各种标记的属性是如何的呢?我们使用中会有什么特点呢?那么让我们来具体看看。
C#文档XML标记的介绍
<c>:指示这行注释标识为Code
<code>:指示多行注释标识为Code
<example>:经常与<code>连用,用来给出如何使用某些成员的例子。
<exception>:指明一个成员会抛出哪些异常,经常与cref属性连用。
<include>:指明注释在哪些文件中,以及位置。
<list>:用来定义表头,经常与<item>连用
<newpara>:内部使用,如<remarks>或<returns>。让用户有机会给注释文本加入其他的结构。
<param>:说明参数的属性,编译器会检查参数的合法性。如果通不过,会在文档中产生!标识的警告。
<paramref>:类似<param>。
<permission>:标明用于成员的代码存取的安全性。
<remarks>:用于描述class或其它类型的描述性文字,不涉及具体细节(如果是这样,使用<summary>)。
<returns>:描述方法或函数的返回值。
<see>:指定一个链接。
<seealso>:指定要出现在See Also部分的文本。
<summary>:类型的描述性文字。它会被vs.net内置的IntelliSense使用并显示在对应的类型中。(即在vs.net中击键“.”出现的提示)
<value>:描述属性。
标记及描述
cref:可用于任何标记来提供一个代码元素的参考。编译器将检查这个代码元素是否存在,如不存在则在文档中用!标识。
name:用于<param>或<paramref>
C#文档XML标记使用的例子
1.<param>标记
/// <summary>
/// A method with a string array param.
/// </summary>
/// <param name="ss"></param>
public void Koo(string[] ss) {}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
2.<returns>标记
/// <summary>
/// A nonvoid method.
/// </summary>
/// <returns>The result of the operation.</returns>
public int Noo() { return 0; }
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
3.<exception>标记和cref 属性:
/// <summary>
/// <exception cref="System.Exception">
/// Throws a FileIOException when...
/// </exception>
/// </summary>
public void Foo() {}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
4.<c>, <code>, 和<example>标记
/// <summary>
/// <c>Hoo</c> is a method in the <c>Class1</c> class.
/// </summary>
public void Hoo() {}
/// <summary>
/// The Joo method.
/// <example>This example shows how to use Joo:
/// <code>
/// <newpara/>
/// public static void Main()
/// {
/// Console.WriteLine(Class1.Joo());
/// }
/// <newpara/>
/// </code>
/// </example>
/// </summary>
public static int Joo() { return 0; }
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
5.<include> 标记语法:
<include file=''''filename'''' path=''''tagpath[@name="id"]'''' />
/// <include file=''''supporting.xml'''' path=''''MyDocs/MyMembers[@name="Class1"]/*'''' />
class Class1{
public static void Main() {}
}
supporting.xml
<MyDocs>
<MyMembers name="Class1">
<summary>
The summary for this type.
</summary>
</MyMembers>
<MyMembers name="Class2">
<summary>
Another type description.
</summary>
</MyMembers>
</MyDocs>
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
6.<list>标记语法及应用
<list type="bullet" │ "number" │ "table">
<listheader>
<term>term</term>
<description>description</description>
</listheader>
<item>
<term>term</term>
<description>description</description>
</item>
</list>
/// <remarks>Here is an example of a bulleted list:
/// <list type="bullet">
/// <item>
/// <description>Item 1.</description>
/// </item>
/// <item>
/// <description>Item 2.</description>
/// </item>
/// </list>
/// </remarks>
static void Main(string[] args) {}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
C#文档XML标记的基本内容就向你介绍到这里,希望对你了解和学习C#文档XML标记有所帮助。
【编辑推荐】