詳解C#文檔XML標記
C#文檔XML標記是我們在C#文檔制作的時候必須要使用的,那么關于C#文檔XML標記的各種標記的屬性是如何的呢?我們使用中會有什么特點呢?那么讓我們來具體看看。
C#文檔XML標記的介紹
<c>:指示這行注釋標識為Code
 
<code>:指示多行注釋標識為Code
 
<example>:經常與<code>連用,用來給出如何使用某些成員的例子。
 
<exception>:指明一個成員會拋出哪些異常,經常與cref屬性連用。
 
<include>:指明注釋在哪些文件中,以及位置。
 
<list>:用來定義表頭,經常與<item>連用
 
<newpara>:內部使用,如<remarks>或<returns>。讓用戶有機會給注釋文本加入其他的結構。
 
<param>:說明參數(shù)的屬性,編譯器會檢查參數(shù)的合法性。如果通不過,會在文檔中產生!標識的警告。
 
<paramref>:類似<param>。
 
<permission>:標明用于成員的代碼存取的安全性。
 
<remarks>:用于描述class或其它類型的描述性文字,不涉及具體細節(jié)(如果是這樣,使用<summary>)。
 
<returns>:描述方法或函數(shù)的返回值。
 
<see>:指定一個鏈接。
 
<seealso>:指定要出現(xiàn)在See Also部分的文本。
 
<summary>:類型的描述性文字。它會被vs.net內置的IntelliSense使用并顯示在對應的類型中。(即在vs.net中擊鍵“.”出現(xiàn)的提示)
 
<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) {}
 
2.<returns>標記
- /// <summary>
 - /// A nonvoid method.
 - /// </summary>
 - /// <returns>The result of the operation.</returns>
 - public int Noo() { return 0; }
 
3.<exception>標記和cref 屬性:
- /// <summary>
 - /// <exception cref="System.Exception">
 - /// Throws a FileIOException when...
 - /// </exception>
 - /// </summary>
 - public void Foo() {}
 
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; }
 
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>
 
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) {}
 
C#文檔XML標記的基本內容就向你介紹到這里,希望對你了解和學習C#文檔XML標記有所幫助。
【編輯推薦】















 
 
 
 
 
 
 