C#文档注释规范示例(转)

C#文档注释规范示例源代码(摘自微软C# Language Specification),转到这里看得方便些,免得我每次到处找,发现博客是个不错的东东,嘿嘿:
namespace Graphics
{

/// <summary>Class <c>Point</c> models a point in a two-dimensional plane.
/// </summary>

public class Point 
{
    
/// <summary>Instance variable <c>x</c> represents the point's
    
///    x-coordinate.</summary>

    private int x;
    
/// <summary>Instance variable <c>y</c> represents the point's
    
///    y-coordinate.</summary>

    private int y;
    
/// <value>Property <c>X</c> represents the point's x-coordinate.</value>
    public int X
    
{
        
get return x; }
        
set { x = value; }
    }

    
/// <value>Property <c>Y</c> represents the point's y-coordinate.</value>
    public int Y
    
{
        
get return y; }
        
set { y = value; }
    }

    
/// <summary>This constructor initializes the new Point to
    
///    (0,0).</summary>

    public Point() : this(0,0{}
    
/// <summary>This constructor initializes the new Point to
    
///    (<paramref name="xor"/>,<paramref name="yor"/>).</summary>
    
/// <param><c>xor</c> is the new Point's x-coordinate.</param>
    
/// <param><c>yor</c> is the new Point's y-coordinate.</param>

    public Point(int xor, int yor) {
        X 
= xor;
        Y 
= yor;
    }

    
/// <summary>This method changes the point's location to
    
///    the given coordinates.</summary>
    
/// <param><c>xor</c> is the new x-coordinate.</param>
    
/// <param><c>yor</c> is the new y-coordinate.</param>
    
/// <see cref="Translate"/>

    public void Move(int xor, int yor) {
        X 
= xor;
        Y 
= yor;
    }

    
/// <summary>This method changes the point's location by
    
///    the given x- and y-offsets.
    
/// <example>For example:
    
/// <code>
    
///    Point p = new Point(3,5);
    
///    p.Translate(-1,3);
    
/// </code>
    
/// results in <c>p</c>'s having the value (2,8).
    
/// </example>
    
/// </summary>
    
/// <param><c>xor</c> is the relative x-offset.</param>
    
/// <param><c>yor</c> is the relative y-offset.</param>
    
/// <see cref="Move"/>

    public void Translate(int xor, int yor) {
        X 
+= xor;
        Y 
+= yor;
    }

    
/// <summary>This method determines whether two Points have the same
    
///    location.</summary>
    
/// <param><c>o</c> is the object to be compared to the current object.
    
/// </param>
    
/// <returns>True if the Points have the same location and they have
    
///    the exact same type; otherwise, false.</returns>
    
/// <seealso cref="operator=="/>
    
/// <seealso cref="operator!="/>

    public override bool Equals(object o) {
        
if (o == null{
            
return false;
        }

        
if (this == o) {
            
return true;
        }

        
if (GetType() == o.GetType()) {
            Point p 
= (Point)o;
            
return (X == p.X) && (Y == p.Y);
        }

        
return false;
    }

    
/// <summary>Report a point's location as a string.</summary>
    
/// <returns>A string representing a point's location, in the form (x,y),
    
///    without any leading, training, or embedded whitespace.</returns>

    public override string ToString() {
        
return "(" + X + "," + Y + ")";
    }

    
/// <summary>This operator determines whether two Points have the same
    
///    location.</summary>
    
/// <param><c>p1</c> is the first Point to be compared.</param>
    
/// <param><c>p2</c> is the second Point to be compared.</param>
    
/// <returns>True if the Points have the same location and they have
    
///    the exact same type; otherwise, false.</returns>
    
/// <seealso cref="Equals"/>
    
/// <seealso cref="operator!="/>

    public static bool operator==(Point p1, Point p2) {
        
if ((object)p1 == null || (object)p2 == null{
            
return false;
        }


        
if (p1.GetType() == p2.GetType()) {
            
return (p1.X == p2.X) && (p1.Y == p2.Y);
        }


        
return false;
    }

    
/// <summary>This operator determines whether two Points have the same
    
///    location.</summary>
    
/// <param><c>p1</c> is the first Point to be compared.</param>
    
/// <param><c>p2</c> is the second Point to be compared.</param>
    
/// <returns>True if the Points do not have the same location and the
    
///    exact same type; otherwise, false.</returns>
    
/// <seealso cref="Equals"/>
    
/// <seealso cref="operator=="/>

    public static bool operator!=(Point p1, Point p2) {
        
return !(p1 == p2);
    }

    
/// <summary>This is the entry point of the Point class testing
    
/// program.
    
/// <para>This program tests each method and operator, and
    
/// is intended to be run after any non-trvial maintenance has
    
/// been performed on the Point class.</para></summary>

    public static void Main() {
        
// class test code goes here
    }

}

}


文档生成器根据给定类 Point 的源代码如上所示所产生的XML文档如下:

<?xml version="1.0"?>
<doc>
    
<assembly>
        
<name>Point</name>
    
</assembly>
    
<members>
        
<member name="T:Graphics.Point">
            
<summary>Class <c>Point</c> models a point in a two-dimensional
            plane.
            
</summary>
        
</member>
        
<member name="F:Graphics.Point.x">
            
<summary>Instance variable <c>x</c> represents the point's
            x-coordinate.
</summary>
        
</member>
        
<member name="F:Graphics.Point.y">
            
<summary>Instance variable <c>y</c> represents the point's
            y-coordinate.
</summary>
        
</member>
        
<member name="M:Graphics.Point.#ctor">
            
<summary>This constructor initializes the new Point to
        (0,0).
</summary>
        
</member>
        
<member name="M:Graphics.Point.#ctor(System.Int32,System.Int32)">
            
<summary>This constructor initializes the new Point to
            (
<paramref name="xor"/>,<paramref name="yor"/>).</summary>
            
<param><c>xor</c> is the new Point's x-coordinate.</param>
            
<param><c>yor</c> is the new Point's y-coordinate.</param>
        
</member>
        
<member name="M:Graphics.Point.Move(System.Int32,System.Int32)">
            
<summary>This method changes the point's location to
            the given coordinates.
</summary>
            
<param><c>xor</c> is the new x-coordinate.</param>
            
<param><c>yor</c> is the new y-coordinate.</param>
            
<see cref="M:Graphics.Point.Translate(System.Int32,System.Int32)"/>
        
</member>
        
<member
            
name="M:Graphics.Point.Translate(System.Int32,System.Int32)">
            
<summary>This method changes the point's location by
            the given x- and y-offsets.
            
<example>For example:
            
<code>
            Point p = new Point(3,5);
            p.Translate(-1,3);
            
</code>
            results in 
<c>p</c>'s having the value (2,8).
            
</example>
            
</summary>
            
<param><c>xor</c> is the relative x-offset.</param>
            
<param><c>yor</c> is the relative y-offset.</param>
            
<see cref="M:Graphics.Point.Move(System.Int32,System.Int32)"/>
        
</member>
        
<member name="M:Graphics.Point.Equals(System.Object)">
            
<summary>This method determines whether two Points have the same
            location.
</summary>
            
<param><c>o</c> is the object to be compared to the current
            object.
            
</param>
            
<returns>True if the Points have the same location and they have
            the exact same type; otherwise, false.
</returns>
            
<seealso
      
cref="M:Graphics.Point.op_Equality(Graphics.Point,Graphics.Point)"/>
            
<seealso
      
cref="M:Graphics.Point.op_Inequality(Graphics.Point,Graphics.Point)"/>
        
</member>
        
<member name="M:Graphics.Point.ToString">
            
<summary>Report a point's location as a string.</summary>
            
<returns>A string representing a point's location, in the form
            (x,y),
            without any leading, training, or embedded whitespace.
</returns>
        
</member>
        
<member
       
name="M:Graphics.Point.op_Equality(Graphics.Point,Graphics.Point)">
            
<summary>This operator determines whether two Points have the
            same
            location.
</summary>
            
<param><c>p1</c> is the first Point to be compared.</param>
            
<param><c>p2</c> is the second Point to be compared.</param>
            
<returns>True if the Points have the same location and they have
            the exact same type; otherwise, false.
</returns>
            
<seealso cref="M:Graphics.Point.Equals(System.Object)"/>
            
<seealso
     
cref="M:Graphics.Point.op_Inequality(Graphics.Point,Graphics.Point)"/>
        
</member>
        
<member
      
name="M:Graphics.Point.op_Inequality(Graphics.Point,Graphics.Point)">
            
<summary>This operator determines whether two Points have the
            same
            location.
</summary>
            
<param><c>p1</c> is the first Point to be compared.</param>
            
<param><c>p2</c> is the second Point to be compared.</param>
            
<returns>True if the Points do not have the same location and
            the
            exact same type; otherwise, false.
</returns>
            
<seealso cref="M:Graphics.Point.Equals(System.Object)"/>
            
<seealso
      
cref="M:Graphics.Point.op_Equality(Graphics.Point,Graphics.Point)"/>
        
</member>
        
<member name="M:Graphics.Point.Main">
            
<summary>This is the entry point of the Point class testing
            program.
            
<para>This program tests each method and operator, and
            is intended to be run after any non-trvial maintenance has
            been performed on the Point class.
</para></summary>
        
</member>
        
<member name="P:Graphics.Point.X">
            
<value>Property <c>X</c> represents the point's
            x-coordinate.
</value>
        
</member>
        
<member name="P:Graphics.Point.Y">
            
<value>Property <c>Y</c> represents the point's
            y-coordinate.
</value>
        
</member>
    
</members>
</doc>
posted @ 2007-09-19 10:15  落叶舟  阅读(2217)  评论(0)    收藏  举报