- Article
- 24 minutes to read
This appendix is informative.
D.1 General
C# provides a mechanism for programmers to document their code using comment syntax that includes XML text. In source code files, comments of a specific shape can be used to instruct a tool to create XML from those comments and the preceding source code elements. Comments using this syntax will be invokeddocumentation comments. They must immediately precede a user-defined type (such as a class, delegate, or interface) or member (such as a field, event, property, or method). The XML generation tool is invokedDocumentation generator. (This generator can, but need not, be the C# compiler itself.) The output produced by the documentation generator is invokeddocumentation file. A documentation file is used as input to adocumentation viewer; a tool designed to produce some sort of display of information and associated documentation.
A conforming C# compiler is not required to check the syntax of documentation comments; Such comments are just ordinary comments. However, a compatible compiler can perform this check.
This specification proposes a set of standard tags for use in documentation comments, but use of these tags is not mandatory and other tags can be used if desired as long as the rules of well-formed XML are followed. For CLI-oriented C# implementations, it also contains information about the documentation generator and the documentation file format. Documentation viewer information is not provided.
D.2 Introduction
Comments of a specific shape can be used to instruct a tool to generate XML from these comments and the preceding source code elements. Such comments areone line comments (§6.3.3), which begin with three measures (///
), Ödelimited_comments (§6.3.3) that start with a slash and two asterisks (/**
). They must immediately precede a user-defined type or member that you are annotating. attribute sections (§21.3) are considered part of declarations, so documentation comments must precede all attributes applied to a type or member.
For explanation, the format of document comments is shown below as two grammar rules:Single_Line_Doc_CommentjDelimited_Doc_Comment. However, these are rulesNotPart of the C# grammar, but represent specific formats ofOne_Line_Commentjdelimited_commentLexer Rules.
Syntax:
Single_Line_Doc_Comment : '///' Input_Character* ; Delimited_Doc_Comment : '/**' Delimited_Comment_Section* ASTERISK+ '/' ;
on oneSingle_Line_Doc_Comment, If there is a...blank spacecharacter that follows///
characters in eachSingle_Line_Doc_Commentsnext to the streamSingle_Line_Doc_Comment, For whatblank spacethe character is not included in the XML output.
on oneDelimited_Doc_Comment, if the first is notblank spaceCharacter in the second line is aASTERISKand the same pattern optionalblank spacecharacters and aASTERISKcharacter is repeated at the beginning of each line withinDelimited_Doc_Comment, repeating pattern characters are not included in the XML output. The pattern may containblank spacecharacters after, as well as before, whichASTERISKCharacter.
Example:
/// <summary>/// Class <c>Point</c> models a point on a two-dimensional plane./// </summary>public class Point{ /// <summary> /// Method < c> Sketch</c> draws the point. /// </summary> void Draw() {...}}
Text in documentation comments must be well-formed according to XML rules (http://www.w3.org/TR/REC-xml). If the XML contains errors, a warning is generated and the documentation file contains a comment indicating that an error has occurred.
While developers are free to create their own tags, a recommended set is defined at§D.3. Some of the recommended tags have special meanings:
Him
<Parameter>
The tag is used to describe parameters. If such a tag is used, the documentation generator must verify that the specified parameter exists and that all parameters are described in the documentation comments. If such a check fails, the documentation generator issues a warning.Him
cref
The attribute can be appended to any tag to provide a reference to a code element. The documentation generator needs to verify that this piece of code is present. If the check fails, the documentation generator issues a warning. When looking for one in acref
attribute, the documentation generator must honor namespace visibility as directed in the source code. For generic code elements, normal generic syntax (e.g. "List<T>
) cannot be used because it generates invalid XML. Curly brackets can be used instead of square brackets (e.g.; "List{T}
") or you can use XML escape syntax (e.g. "List<T>
“).Him
<Summary>
The label is intended to be used by a documentation viewer to display additional information about a type or member.Him
<include>
The tag contains information from an external XML file.
Note that the documentation file does not contain complete information about the type and members (ie it does not contain any type information). To obtain this information about a type or member, the documentation file must be used in conjunction with thinking about the type or member.
D.3.1 General
The documentation generator must accept and process all tags that are valid according to the XML rules. The following tags provide commonly used features in the user documentation. (Other tags are of course also possible.)
label | Relation | purpose |
---|---|---|
<c> | §D.3.2 | Set the text to a code-like font |
<Code> | §D.3.3 | Define one or more lines of source code or program output |
<Example> | §D.3.4 | give an example |
<Exception> | §D.3.5 | Identifies the exceptions that a method can throw |
<include> | §D.3.6 | Contains XML from an external file |
<List> | §D.3.7 | Make a list or table |
<a> | §D.3.8 | Allows adding structure to the text |
<Parameter> | §D.3.9 | Describe a parameter for a method or constructor |
<paramref> | §D.3.10 | Identify that a word is a parameter name |
<permission> | §D.3.11 | Document a member's security accessibility |
<Comments> | §D.3.12 | Describe additional information about a type. |
<back> | §D.3.13 | Describe the return value of a method. |
<ver> | §D.3.14 | provide a link |
<see also> | §D.3.15 | generate aalso seeVerboten |
<Summary> | §D.3.16 | Describe a type or a member of a type |
<parameter type> | §D.3.17 | Describe a type parameter for a generic type or method |
<typeparamref> | §D.3.18 | Identify a word is a type parameter name |
<Bravery> | §D.3.19 | describe a property |
D.3.2 <c>
This tag provides a mechanism to indicate that a piece of text within a description should be set to a specific font used for a code block. Use for actual lines of code<Code>
(§D.3.3).
Syntax:
<c>
Text</c>
Example:
/// <summary>/// class <c>Point</c> models a point on a two-dimensional plane./// </summary>public class Point{}
D.3.3 <Code>
This tag is used to define one or more lines of source code or program output for a specific source. Use for small snippets in the narrative<c>
(§D.3.2).
Syntax:
<Code>
Source code or program output</code>
Example:
public class Point{ /// <summary> /// This method changes the position of the point according to the specified x and y offsets. /// <example> /// For example: /// <code> /// Point p = new Point(3,5); /// p.Translate(-1,3); /// </code> /// returns <c>p</c> with the value (2,8). /// </example> /// </summary> public void Translate(int dx, int dy) { ... }}
D.3.4 <Example>
This tag allows example code within a comment to indicate how a method or other library item can be used. Normally this would include using the tag as well<Code>
(§D.3.3) in addition.
Syntax:
<Example>
description</example>
Example:
ver<Code>
(§D.3.3) For example.
D.3.5 <Exception>
This tag provides a way to document the exceptions that a method can throw.
Syntax:
<cref exception="
Member">
description</Exception>
Where from
cref="
Member"
is the name of a member. The documentation generator checks whether the specified member exists and translates itMemberto the canonical element name in the documentation file.- descriptionis a description of the circumstances under which the exception occurs.
Example:
class MasterFileFormatCorruptException : System.Exception { ... } class MasterFileLockedOpenException : System.Exception { ... } public class DataBaseOperations{ /// <exception cref="MasterFileFormatCorruptException"> /// Se lanza cuando el archivo maestro está danificado. /// </Exception> /// <Exception cref="MasterFileLockedOpenException"> /// Se lanza cuando el archivo maestro ya está aberto. /// </exception> public static void ReadRecord(int flag) { if (flag == 1) { throw new MasterFileFormatCorruptException(); } else if (flag == 2) { throw new MasterFileLockedOpenException(); } ... }}
D.3.6 <include>
This tag allows you to include information from an XML document outside of the source code file. The external file must be a well-formed XML document, and an XPath expression is applied to that document to specify which XML from that document to include. Him<include>
The tag is then replaced with the selected XML from the external document.
Syntax:
<include file="
filename"ruta="
XPath" />
Where from
file="
filename"
is the filename of an external XML file. The filename is interpreted relative to the file containing the include tag.path = "
XPath"
is an XPath expression that selects a portion of the XML in the external XML file.
example:
If the source code contained a statement like:
/// <include file="docs.xml" path='extradoc/class[@name="IntList"]/*' />public class IntList { ... }
and the external file "docs.xml" had the following content:
<?xml version="1.0"?><extradoc> <class name="IntList"> <summary> Contains a list of integers. </summary> </class> <class name="StringList"> <summary> Contains a list of strings. </abstract> </class></extradoc>
then the same documentation is generated as if the source code was included:
/// <summary>/// Contains a list of entries./// </summary>public class IntList { ... }
D.3.7 <List>
This tag is used to create a list or table of items. may contain one<list header>
-Block for defining the header of a table or list of definitions. (When defining a table, only one entry forfinishedmust be specified in the header.)
Each item in the list is indicated with an a<Element>
Block. When creating a list of definitions, bothfinishedjdescriptionmust be specified. But only for a table, bulleted list, or numbered listdescriptionmust be specified.
Syntax:
<list type="bookmark" | "Nummer" | "table"> <list header> <term>term</term> <description>description</description> </list header> <element> <term>term</term> <description>description</description> </ element> ... <element> <term>term</term> <description>description</description> </element></list>
Where from
- finishedis the term to be defined, whose definition is indescription.
- descriptionis an item in a numbered or bulleted list, or the definition of afinished.
Example:
public class MyClass{ /// <summary>This is an example of a bulleted list: /// <list type="bullet"> /// <item> /// <description>Item 1.</description> / // </item> /// <item> /// <description>Item 2.</description> /// </item> /// </list> /// </summary> public static void Directors() { ... }}
D.3.8 <Paragraph>
This tag is used in other tags, e.g<Summary>
(§D.3.16) Ö<back>
(§D.3.13) and lets you structure the text.
Syntax:
<a>
contents</para>
Where from
- contentsis the paragraph text.
Example:
public class Point{ /// <summary>This is the entry point of the test program for the Point class. /// <para> /// This program tests all methods and operators /// and is designed to run after /// non-trivial maintenance has been performed on the Point class. /// </para> /// </summary> public static void Main() { ... }}
D.3.9 <Parameter>
This tag is used to describe a parameter for a method, constructor, or indexer.
Syntax:
<Parametername="
Name">
description</parameter>
Where from
- Nameis the name of the parameter.
- descriptionis a description of the parameter.
Example:
public class Point{ /// <summary> /// This method changes the position of the point to /// the provided coordinates. /// </summary> /// <param name="xPosition">the new x-coordinate.</param> /// <param name="yPosition">the new y-coordinate.</param> public void Move(int xPosition, int yPosition) { ... }}
D.3.10 <paramref>
This tag is used to indicate that a word is a parameter. The documentation file can be edited to format this parameter differently.
Syntax:
<paramref name="
Name"/>
Where from
- Nameis the name of the parameter.
Example:
public class Point{ /// <summary>This constructor initializes the new Point to /// (<paramref name="xPosition"/>,<paramref name="yPosition"/>). /// </summary> /// <param name="xPosition">the x-coordinate of the new point.</param> /// <param name="yPosition">the y-coordinate of the new point .< /param > public point(int xPosition, int yPosition) { ... }}
D.3.11 <Permission>
You can use this tag to document the security availability of a member.
Syntax:
<Permission cref="
Member">
description</Permission>
Where from
- Memberis the name of a member. The documentation generator checks whether the specified code element exists and translates itMemberto the canonical element name in the documentation file.
- descriptionis a description of member access.
Example:
public class MyClass{ /// <permission cref="System.Security.PermissionSet"> /// Tods podem accessar este método. /// </permiso> public static void Test() { ... }}
D.3.12 <Remarks>
This tag is used to provide additional information about a type. Use<Summary>
(§D.3.16) to describe the type itself and the members of a type.
Syntax:
<Comments>
description</comments>
Where from
- descriptionis the text of the observation.
Example:
/// <summary>/// The <c>Point</c> class models a point on a two-dimensional plane./// </summary>/// <remarks>/// Use polar coordinates // / < / remarks>Public Class Point{ ...}
D.3.13 <Returns>
This tag is used to describe the return value of a method.
Syntax:
<back>
description</return>
Where from
- descriptionis a description of the return value.
Example:
public class Point{ /// <summary> /// Reports the position of a point as a string. /// </summary> /// <returns> /// A string representing the position of a point, in the form (x,y), /// with no leading, trailing, or embedded spaces. /// </returns> replacement public string ToString() => $"({X},{Y})"; public int X { get; put on; } public int Y { get; put on; }}
D.3.14 <ver>
With this tag you can specify a link within the text. Use<see also>
(§D.3.15) to specify the text that will appear in aalso seeSubordinate clause.
Syntax:
<ver cref="
Member"href="
URL"idiomatic word="
keyword" />
Where from
- Memberis the name of a member. The documentation generator verifies that the specified piece of code exists and changesMemberto the element name in the generated documentation file.
- URLis a link to an external source.
- idiomatic wordIt's a word to stand out in any way.
Example:
public class Point{ /// <summary> /// This method changes the position of the point to /// the provided coordinates. <see cref="Translate"/> /// </summary> public void Move(int xPosition, int yPosition) { ... } /// <summary>This method changes the position of the given point /// x - and compensate e.g. <ver cref="Move"/> /// </summary> public void Translate(int dx, int dy) { ... }}
D.3.15 <see also>
You can use this tag to generate an entry for thealso seeSubordinate clause. Use<ver>
(§D.3.14) to specify a link in the text.
Syntax:
<see also cref="
Member"href="
URL" />
Where from
- Memberis the name of a member. The documentation generator verifies that the specified piece of code exists and changesMemberto the element name in the generated documentation file.
- URLis a link to an external source.
Example:
public class Point{ /// <summary> /// This method determines whether two points have the same position. /// </summary> /// <seealso cref="operator=="/> /// <seealso cref="operator!="/> public override bool Equals(object o) { ... }}
D.3.16 <Summary>
This tag can be used to describe a type or a member of a type. Use<Comments>
(§D.3.12) to describe the type itself.
Syntax:
<Summary>
description</abstract>
Where from
- descriptionis a summary of the type or member.
Example:
public class Point{ /// <summary> /// This constructor initializes the new Point at /// (<paramref name="xPosition"/>,<paramref name="yPosition"/>). /// </summary> public Point(int xPosition, int yPosition) { ... } /// <summary>This constructor initializes the new Point en (0,0).</summary> public Point() : this (0, 0) { }}
D.3.17 <Parametertyp>
This tag is used to describe a type parameter for a generic type or method.
Syntax:
<typeparam name="
Name">
description</tip frame>
Where from
- Nameis the name of the type parameter.
- descriptionis a description of the type parameter.
Example:
/// <summary>A generic list class.</summary>/// <typeparam name="T">The type stored by the list.</typeparam>public class MyList<T>{ ...}
D.3.18 <typeparamref>
This tag is used to indicate that a word is a type parameter. The documentation file can be processed to format this type parameter in other ways.
Syntax:
<typeparamref name="
Name"/>
Where from
- Nameis the name of the type parameter.
Example:
public class MyClass{ /// <summary> /// This method retrieves data and returns a list of /// <typeparamref name="T"/> . /// </summary> /// <param name="string">Query to run</param> public List<T> FetchData<T>(string query) { ... }}
D.3.19 <value>
You can use this tag to describe a property.
Syntax:
<Bravery>
object description</wert>
Where from
- object descriptionis an object description.
Example:
public class Point{ /// <value>Property <c>X</c> represents the x coordinate of the point.</value> public int X { get; Color; }}
D.4 Processing of Documentation Files
D.4.1 General
The following information applies to CLI-oriented C# implementations.
The documentation generator generates an identification string for each source code element marked with a documentation comment. This ID string uniquely identifies a source item. A documentation viewer can use an identification string to identify the corresponding item to which the documentation relates.
The documentation file is not a hierarchical representation of the source code; Instead, it's a flat list with an ID string generated for each item.
D.4.2 Format this String ID
The documentation generator observes the following rules when generating identification strings:
No spaces are inserted into the string.
The first part of the string identifies the type of documented member by a single character followed by a colon. The following types of members are defined:
Character description mi Fall F campo METRO Method (including constructors, finalizers, and operators) Norte namespace PAG property (including indexers) T Type (e.g. class, delegate, enumeration, interface and structure) ! error string; the rest of the string gives information about the error. For example, the documentation generator generates error information for links that cannot be resolved. The second part of the string is the full name of the element, starting at the root of the namespace. The element name, attached types, and namespace are separated by periods. If the element name itself contains periods, they are replaced with # (U+0023) characters. (It is assumed that no element has this character in its name.)
For methods and properties with arguments, the list of arguments follows in parentheses. For those with no arguments, the parentheses are omitted. The arguments are separated by commas. The encoding of each argument is the same as for a CLI signature, as follows:
- Arguments are represented by their documentation name, which is based on their fully qualified name modified as follows:
- Arguments representing generic types have a "
'
Character " followed by the number of type parameters - arguments that have
For a
Öreferee
hat modifier a@
after its type name. By value or via arguments passedParameter
They have no special notation. - Arguments that are arrays are represented as
[
lower limit:
Talla,
…,
lower limit:
Talla]
where the number of commas is unranked and the lower bounds and size of each dimension, if known, are represented in decimals. If no lower limit or size is specified, it is ignored. If the lower bound and size of a given dimension are omitted, ":
“ is also omitted. Irregular matrices are indicated by a "[]
“ per level. - Arguments with pointer types other than
file
are represented by a*
after the type name. Afile
Pointer is represented by a type nameSystem.Empty
. - Arguments referring to generic type parameters defined in types are terminated with the "
`
” followed by the zero-based index of the type parameter. - Arguments that take generic type parameters defined in methods use a double backtil."
„
" rather than"`
' used for types. - Arguments referring to constructed generic types are encoded with the generic type followed by "
{
' followed by a comma-separated list of type arguments, followed by '}
“.
- Arguments representing generic types have a "
- Arguments are represented by their documentation name, which is based on their fully qualified name modified as follows:
D.4.3 Examples of ID strings
Each of the following examples shows a C# code snippet along with the ID string generated by each source element that can contain a documentation comment:
The typeare represented by their full name and general information:
enum Color { Rot, Blau, Grün } namespace Acme{ interface IProcess { ... } struct ValueType { ... } class Widget : IProcess { public class NestedClass { ... } public interface IMenuItem { ... } public delegado vacío Supr(int i); public enum Direção { Norte, Sur, Este, Oeste } } class MinhaLista<T> { class Helper<U,V> { ... } }}
tags:
"T:Color""T:Acme.IProcess""T:Acme.ValueType""T:Acme.Widget""T:Acme.Widget.NestedClass""T:Acme.Widget.IMenuItem""T:Acme.Widget .Del""T:Acme.Widget.Direction""T:Acme.MinhaLista`1""T:Acme.MinhaLista`1.Helper`2"
The fieldsthey are represented by their fully qualified names.
Namespace Acme{ struct ValueType { private int total; } Widget Class: IProcess { public class NestedClass { private int value; } private string message; private static color default color; double private constant PI = 3.14159; monthly average read-only, double-protected; long array private1[]; private Widget[,] array2; private not sure int *pCount; private unsafe float **ppValues; }}
tags:
"F:Acme.ValueType.total""F:Acme.Widget.NestedClass.value""F:Acme.Widget.message""F:Acme.Widget.defaultColor""F:Acme.Widget.PI""F: Acme.Widget.monthlyAverage""F:Acme.Widget.array1""F:Acme.Widget.array2""F:Acme.Widget.pCount""F:Acme.Widget.ppValues"
builders
namespace Acme{ class Widget : IProcess { static Widget() { ... } public Widget() { ... } public Widget(string s) { ... } }};
tags:
"M:Acme.Widget.#cctor""M:Acme.Widget.#ctor""M:Acme.Widget.#ctor(System.String)"
Finisher
namespace Acme{ class Widget : IProcess { ~Widget() { ... } }}
tags:
"M:Acme.Widget.Finalizar"
methods
espaço de nombres Acme{ struct ValueType { public void M(int i) { ... } } class Widget : IProcess { public class NestedClass { public void M(int i) { ... } } public static void M0() { .. . } public void M1(char c, out float f, ref ValueType v) { ... } public void M2 (short[] x1, int[,] x2, long[][] x3) { ... } public void M3(long[][] x3, Widget[][,,] x4) { ... } public unsicher void M4(char *pc, Color **pf) { ... } public unsicher void M5(void * pv , double *[][,] pd) { ... } public void M6(int i, params object[] args) { ... } } class MyList<T> { public void Test(T t) { . .. } } class UseList { public void Process(MyList<int> list) { ... } public MyList<T> GetValues<T>(T value) { ... } }}
tags:
"M:Acme.ValueType.M(System.Int32)""M:Acme.Widget.NestedClass.M(System.Int32)""M:Acme.Widget.M0""M:Acme.Widget.M1(System.Int32)""M:Acme.Widget.M0""M:Acme.Widget.M1(System. Char,System.Single@,Acme.ValueType@)""M:Acme.Widget.M2(System.Int16[],System.Int32[0:,0:],System.Int64[][])""M :Acme.Widget.M3(System.Int64[][],Acme.Widget[0:,0:,0:][])""M:Acme.Widget.M4(System.Char*,Color**) ""M:Acme.Widget.M5(System.Void*,System.Double*[0:,0:][])""M:Acme.Widget.M6(System.Int32,System.Object[])" "M:Acme.MyList`1.Test(`0)""M:Acme.UseList.Process(Acme.MyList{System.Int32})""M:Acme.UseList.GetValues``1(``0) "
Properties and indexers
namespace Acme{ class Widget : IProcess { public int Width { get { ... } set { ... } } public int this[int i] { get { ... } set { ... } } public int this[ string s, int i] { bekomme { ... } set { ... } } }}
tags:
"P:Acme.Widget.Width""P:Acme.Widget.Item(System.Int32)""P:Acme.Widget.Item(System.String,System.Int32)"
events
namespace Acme{ class Widget : IProcess { public event Del AnEvent; }}
tags:
"E:Acme.Widget.AnEvent"
unary operators
namespace Acme{ class Widget : IProcess { public static Widget operator+(Widget x) { ... } }}
tags:
"M:Acme.Widget.op_UnaryPlus(Acme.Widget)"
The full set of unary operator function names used are as follows:op_UnaryPlus
,op_UnaryNegation
,op_LogicalNot
,op_OnesComplemento
,on_increment
,op_Decrement
,op_True
, Sheon_False
.
binary operators
namespace Acme{ class Widget : IProcess { public static Widget operator+(Widget x1, Widget x2) { ... } }};
tags:
"M:Acme.Widget.op_Addition(Acme.Widget,Acme.Widget)"
The full set of binary operator function names used are as follows:op_addition
,op_subtraction
,op_Multiply
,op_department
,in_module
,de_BitwiseY
,op_BitwiseO
,op_ExclusiveO
,on_LeftShift
,op_RightShift
,op_Equality
,op_inequality
,op_Menos de
,op_less than equal
,op_greater than
, Sheop_MayorQueOIgual
.
conversion operatorsThere's a track"~
” followed by the return type.
Namespace Acme{ Widget class: IProcess { public explicit static operator int(Widget x) { ... } public static implicit operator long(Widget x) { ... } }}
tags:
"M:Acme.Widget.op_Explicit(Acme.Widget)~System.Int32""M:Acme.Widget.op_Implicit(Acme.Widget)~System.Int64"
D.5 An example
D.5.1 C# Source Code
The following example shows the source code for a Point class:
namespace Graphics{ /// <summary> /// The <c>Point</c> class models a point on a two-dimensional plane. /// </summary> public class Point { /// <value> /// property <c>X</c> represents the x coordinate of the point. /// </value> public int X { get; put on; } /// <value> /// The <c>Y</c> property represents the y coordinate of the point. /// </value> public int Y { get; put on; } /// <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="xPosition"/>, <paramref name="yPosition"/>). /// </summary> /// <param><c>xPosition</c> is the new x coordinate of the point.</param> /// <param><c>yPosition</c> is the new The y-coordinate of the point.</param> public Point(int xPosition, int yPosition) { X = xPosition; Y = location y; } /// <summary> /// This method changes the position of the point to /// the specified coordinates. <see cref="Translate"/> /// </summary> /// <param><c>xPosition</c> is the new x coordinate.</param> /// <param><c> yPosition </c> is the new y-coordinate.</param> public void Move(int xPosition, int yPosition) { X = xPosition; Y = location y; } /// <summary> /// This method changes the position of the point by /// the specified x and y offsets. /// <Example>For example: /// <Code> /// Point p = new Point(3, 5); /// p.Translate(-1, 3); /// </code> /// returns <c>p</c> with the value (2, 8). /// <ver cref="Move"/> /// </example> /// </summary> /// <param><c>dx</c> is the relative x offset.</param > /// <param><c>dy</c> is the relative y offset.</param> public void Translate(int dx, int dy) { X += dx; Y + = dy; } /// <summary> /// This method determines whether two points have the same position. /// </summary> /// <param> /// <c>o</c> is the object to compare to the current object. /// </param> /// <returns> /// True if the points have the same position and /// exactly the same type; otherwise wrong. /// </returns> /// <see also cref="operator=="/> /// <see also cref="operator!="/> public override bool Equals(object o) { if (o = = null ) {returns false; } if ((Object) this == o) { return true; } if (GetType() == o.GetType()) { Point p = (Point)o; return (X == p.X) && (Y == p.Y); } returns false; } /// <summary> /// This method returns the hash code of a point. /// </summary> /// <returns> /// The hash code int. /// </returns> public override int GetHashCode() { return X + (Y >> 4); // a raw version } /// <summary>Returns the position of a point as a string.</summary> /// <returns> /// A string representing the position of a point in the form (x , y ), / // no leading, training, or embedded spaces. /// </returns> replacement public string ToString() => $"({X},{Y})"; /// <summary> /// This operator determines whether two points have the same position. /// </summary> /// <param><c>p1</c> is the first point to compare.</param> /// <param><c>p2</c> is the second to comparing point.</param> /// <returns> /// True if the points have the same position and /// exactly the same type; otherwise wrong. /// </returns> /// <see also cref="Equals"/> /// <see also cref="operator!="/> public static bool operator==(Point p1, Point p2) { if ((object)p1 == null || (object)p2 == null) { returns false; } if (p1.GetType() == p2.GetType()) { return (p1.X == p2.X) && (p1.Y == p2.Y); } returns false; } /// <summary> /// This operator determines whether two points have the same position. /// </summary> /// <param><c>p1</c> is the first point to compare.</param> /// <param><c>p2</c> is the second to comparing point.</param> /// <returns> /// True if the points do not have the same position and /// exactly the same type; otherwise wrong. /// </returns> /// <see also cref="Equals"/> /// <see also cref="operator=="/> public static bool operator!=(Point p1, Point p2) => !( p1 == p2); }}
D.5.2 Resultierendes XML
Here is the output produced by a documentation generator when given the source code for the classpoint it out
, shown above:
<?xml version="1.0"?><doc> <assembly> <name>Point</name> </assembly> <members> <member name="T:Graphics.Point"> <abstract>Class <c > Point</c> models a point on a two-dimensional plane. </summary> </member> <member name="M:Graphics.Point.#ctor"> <summary>This constructor initializes the new Point to (0, 0).</summary> </member> <name of the member="M:Graphics.Point.#ctor(System.Int32,System.Int32)"> <summary> This constructor initializes the new Point at (<paramref name="xPosition"/>,<paramref name="yor " />). </summary> <param><c>xPosition</c> is the x coordinate of the new point.</param> <param><c>yPosition</c> is the y coordinate of the new point.</ param> param> </member> <member name="M:Graphics.Point.Move(System.Int32,System.Int32)"> <summary> This method changes the position of the point to the specified coordinates. <see cref="M:Graphics.Point.Translate(System.Int32,System.Int32)"/> </summary> <param><c>xPosition</c> is the new x coordinate.</param> < param><c>yPosition</c> is the new y coordinate.</param> </member> <member name="M:Graphics.Point.Translate(System.Int32,System.Int32)"> < abstract> This method changes the position of the point by the specified x and y offsets. <example>For example: <code> point p = new point(3,5); p. Translate(-1,3); </code> yields <c>p</c> with the value (2,8). </example> <see cref="M:Graphics.Point.Move(System.Int32,System.Int32)"/> </summary> <param><c>dx</c> is the relative x displacement. </param> <param><c>dy</c> is the relative y offset.</param> </member> <member name="M:Graphics.Point.Equals(System.Object)"> < abstract > This method determines whether two points have the same position. </summary> <param> <c>o</c> is the object to compare to the current object. </param> <returns> True if the points have the same position and are of exactly the same type; otherwise wrong. </returns> <see also cref="M:Graphics.Point.op_Equality(Graphics.Point,Graphics.Point)" /> <see also cref="M:Graphics.Point.op_Inequality(Graphics.Point,Graphics.Point ) " /> </member> <member name="M:Graphics.Point.ToString"> <summary> Reports the position of a point as a string. </summary> <returns> A string representing the position of a point, in the form (x,y), with no leading, formation, or embedded spaces. </returns> </member> <member name="M:Graphics.Point.op_Equality(Graphics.Point,Graphics.Point)"> <summary> This operator determines whether two points have the same position. </summary> <param><c>p1</c> is the first point to compare.</param> <param><c>p2</c> is the second point to compare.</param> <returns > True if the points have the same position and are of exactly the same type; otherwise wrong. </returns> <see also cref="M:Graphics.Point.Equals(System.Object)"/> <see also 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 position. </summary> <param><c>p1</c> is the first point to compare.</param> <param><c>p2</c> is the second point to compare.</param> <returns > True if the points do not have the same position and exactly the same type; otherwise wrong. </returns> <see also cref="M:Graphics.Point.Equals(System.Object)"/> <see also 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 test program. <para> This program tests each method and operator and is designed to be run after all non-trivial maintenance has been performed on the Point class. </para> </summary> </member> <member name="P:Graphics.Point.X"> <value> The <c>X</c> property represents the x-coordinate of the point. </value> </member> <member name="P:Graphics.Point.Y"> <value> Property <c>Y</c> represents the y-coordinate of the point. </value> </member> </members></doc>
End of information text.