详解C#文档XML标记

开发 后端
C#文档XML标记的属性和使用在我们开发过程中经常会用,那么这里就向你介绍C#文档XML标记的属性和特点以及应用实例,希望对你学习C#文档XML标记有所帮助。

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>标记

  1. /// <summary>  
  2.  
  3. /// A method with a string array param.  
  4.  
  5. /// </summary>  
  6.  
  7. /// <param name="ss"></param>  
  8.  
  9. public void Koo(string[] ss) {}  

2.<returns>标记

  1. /// <summary>  
  2.  
  3. /// A nonvoid method.  
  4.  
  5. /// </summary>  
  6.  
  7. /// <returns>The result of the operation.</returns>  
  8.  
  9. public int Noo() { return 0; }  

3.<exception>标记和cref 属性:

  1. /// <summary>  
  2.  
  3. /// <exception cref="System.Exception">  
  4.  
  5. /// Throws a FileIOException when...  
  6.  
  7. /// </exception>  
  8.  
  9. /// </summary>  
  10.  
  11. public void Foo() {} 

4.<c>, <code>, 和<example>标记

  1. /// <summary>  
  2.  
  3. /// <c>Hoo</c> is a method in the <c>Class1</c> class.  
  4.  
  5. /// </summary>  
  6.  
  7. public void Hoo() {}  
  8.  
  9.    
  10.  
  11. /// <summary>  
  12.  
  13. /// The Joo method.  
  14.  
  15. /// <example>This example shows how to use Joo:  
  16.  
  17. /// <code>  
  18.  
  19. /// <newpara/>  
  20.  
  21. /// public static void Main()  
  22.  
  23. /// {  
  24.  
  25. ///     Console.WriteLine(Class1.Joo());  
  26.  
  27. /// }  
  28.  
  29. /// <newpara/>  
  30.  
  31. /// </code>  
  32.  
  33. /// </example>  
  34.  
  35. /// </summary>  
  36.  
  37. public static int Joo() { return 0; }  

5.<include> 标记语法:

  1. <include file=''''filename'''' path=''''tagpath[@name="id"]'''' />  
  2.  
  3.    
  4.  
  5. /// <include file=''''supporting.xml'''' path=''''MyDocs/MyMembers[@name="Class1"]/*'''' />  
  6.  
  7. class Class1{  
  8.  
  9. public static void Main() {}  
  10.  
  11. }  
  12.  
  13. supporting.xml  
  14.  
  15. <MyDocs>  
  16.  
  17.     <MyMembers name="Class1">  
  18.  
  19.         <summary>  
  20.  
  21.         The summary for this type.  
  22.  
  23.         </summary>  
  24.  
  25.     </MyMembers>  
  26.  
  27.     <MyMembers name="Class2">  
  28.  
  29.         <summary>  
  30.  
  31.         Another type description.  
  32.  
  33.         </summary>  
  34.  
  35.     </MyMembers>  
  36.  
  37. </MyDocs>  

6.<list>标记语法及应用

  1. <list type="bullet" │ "number" │ "table">  
  2.  
  3.     <listheader>  
  4.  
  5.         <term>term</term>  
  6.  
  7.         <description>description</description>  
  8.  
  9.     </listheader>  
  10.  
  11.     <item>  
  12.  
  13.         <term>term</term>  
  14.  
  15.         <description>description</description>  
  16.  
  17.     </item>  
  18.  
  19. </list>  
  20.  
  21.    
  22.  
  23. /// <remarks>Here is an example of a bulleted list:  
  24.  
  25. /// <list type="bullet">  
  26.  
  27. /// <item>  
  28.  
  29. /// <description>Item 1.</description>  
  30.  
  31. /// </item>  
  32.  
  33. /// <item>  
  34.  
  35. /// <description>Item 2.</description>  
  36.  
  37. /// </item>  
  38.  
  39. /// </list>  
  40.  
  41. /// </remarks>  
  42.  
  43. static void Main(string[] args) {}  

C#文档XML标记的基本内容就向你介绍到这里,希望对你了解和学习C#文档XML标记有所帮助。

【编辑推荐】

  1. C#调用浏览器的原理及实现浅析
  2. C#文件浏览器制作的详细过程
  3. C#货币格式转化实例解析
  4. 浅析C#文档自动化实现
  5. C#文档输出的类型描述符浅析

 

责任编辑:仲衡 来源: host01.com
相关推荐

2009-08-18 17:08:50

C#编写XML文档

2009-08-24 17:24:28

C#创建XML文档

2009-08-24 17:46:54

C#创建XML文档

2009-08-12 15:26:38

C#读取XML文档

2009-08-18 17:05:08

C#操作xml文件

2009-08-12 16:26:30

C#读取XML文档

2009-08-12 16:46:22

C#读取XML文档

2009-08-26 11:32:37

C#打印文档

2009-09-09 18:20:29

C# XML编程

2009-08-18 16:42:49

C# 操作XML

2009-08-19 16:42:41

C#如何使用XML

2009-09-09 13:57:28

C# XML解析

2009-08-18 16:30:41

C# 操作XML

2010-09-28 11:03:19

XML DOM

2009-09-01 09:12:37

C# System.X

2009-09-09 14:40:15

C# XML解析

2009-08-25 11:10:20

C#编程实现显示XML

2009-09-09 18:00:55

C# XML编程

2009-08-14 17:09:48

C#引用类型

2009-09-09 14:04:18

C# XML解析XML解析方法
点赞
收藏

51CTO技术栈公众号