詳解C#文檔XML標(biāo)記
C#文檔XML標(biāo)記是我們?cè)贑#文檔制作的時(shí)候必須要使用的,那么關(guān)于C#文檔XML標(biāo)記的各種標(biāo)記的屬性是如何的呢?我們使用中會(huì)有什么特點(diǎn)呢?那么讓我們來(lái)具體看看。
C#文檔XML標(biāo)記的介紹
<c>:指示這行注釋標(biāo)識(shí)為Code
<code>:指示多行注釋標(biāo)識(shí)為Code
<example>:經(jīng)常與<code>連用,用來(lái)給出如何使用某些成員的例子。
<exception>:指明一個(gè)成員會(huì)拋出哪些異常,經(jīng)常與cref屬性連用。
<include>:指明注釋在哪些文件中,以及位置。
<list>:用來(lái)定義表頭,經(jīng)常與<item>連用
<newpara>:內(nèi)部使用,如<remarks>或<returns>。讓用戶有機(jī)會(huì)給注釋文本加入其他的結(jié)構(gòu)。
<param>:說(shuō)明參數(shù)的屬性,編譯器會(huì)檢查參數(shù)的合法性。如果通不過,會(huì)在文檔中產(chǎn)生!標(biāo)識(shí)的警告。
<paramref>:類似<param>。
<permission>:標(biāo)明用于成員的代碼存取的安全性。
<remarks>:用于描述class或其它類型的描述性文字,不涉及具體細(xì)節(jié)(如果是這樣,使用<summary>)。
<returns>:描述方法或函數(shù)的返回值。
<see>:指定一個(gè)鏈接。
<seealso>:指定要出現(xiàn)在See Also部分的文本。
<summary>:類型的描述性文字。它會(huì)被vs.net內(nèi)置的IntelliSense使用并顯示在對(duì)應(yīng)的類型中。(即在vs.net中擊鍵“.”出現(xiàn)的提示)
<value>:描述屬性。
標(biāo)記及描述
cref:可用于任何標(biāo)記來(lái)提供一個(gè)代碼元素的參考。編譯器將檢查這個(gè)代碼元素是否存在,如不存在則在文檔中用!標(biāo)識(shí)。
name:用于<param>或<paramref>
C#文檔XML標(biāo)記使用的例子
1.<param>標(biāo)記
- /// <summary>
- /// A method with a string array param.
- /// </summary>
- /// <param name="ss"></param>
- public void Koo(string[] ss) {}
2.<returns>標(biāo)記
- /// <summary>
- /// A nonvoid method.
- /// </summary>
- /// <returns>The result of the operation.</returns>
- public int Noo() { return 0; }
3.<exception>標(biāo)記和cref 屬性:
- /// <summary>
- /// <exception cref="System.Exception">
- /// Throws a FileIOException when...
- /// </exception>
- /// </summary>
- public void Foo() {}
4.<c>, <code>, 和<example>標(biāo)記
- /// <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> 標(biāo)記語(yǔ)法:
- <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>標(biāo)記語(yǔ)法及應(yīng)用
- <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標(biāo)記的基本內(nèi)容就向你介紹到這里,希望對(duì)你了解和學(xué)習(xí)C#文檔XML標(biāo)記有所幫助。
【編輯推薦】
- C#調(diào)用瀏覽器的原理及實(shí)現(xiàn)淺析
- C#文件瀏覽器制作的詳細(xì)過程
- C#貨幣格式轉(zhuǎn)化實(shí)例解析
- 淺析C#文檔自動(dòng)化實(shí)現(xiàn)
- C#文檔輸出的類型描述符淺析