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

/// <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标记有所帮助。

【编辑推荐】

  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-26 11:32:37

C#打印文档

2009-09-09 18:20:29

C# XML编程

2009-08-12 16:46:22

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-09-01 09:12:37

C# System.X

2010-09-28 11:03:19

XML DOM

2009-08-18 16:30:41

C# 操作XML

2024-07-03 08:21:56

MDI窗体界面

2009-08-14 17:09:48

C#引用类型

2009-09-07 16:13:56

C# MessageB

2009-08-24 11:23:41

C# TimeLabe

2009-09-01 16:07:04

C#命名规约
点赞
收藏

51CTO技术栈公众号