Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
C-sharp language specification.2004.pdf
Скачиваний:
14
Добавлен:
23.08.2013
Размер:
2.55 Mб
Скачать

Annex E Documentation Comments

1Conversion operators have a trailing “~” followed by the return type.

2namespace Acme

3{

4

class Widget: IProcess

5

{

6

public static explicit operator int(Widget x) { … }

7

public static implicit operator long(Widget x) { … }

8}

9}

10"M:Acme.Widget.op_Explicit(Acme.Widget)~System.Int32"

11"M:Acme.Widget.op_Implicit(Acme.Widget)~System.Int64"

12E.4 An example

13E.4.1 C# source code

14The following example shows the source code of a Point class:

15namespace Graphics

16{

17/// <remarks>

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

19/// </remarks>

20public class Point

21{

22

/// <summary>

23

/// Instance variable <c>x</c> represents the Point's x-coordinate.

24

/// </summary>

25

private int x;

26

/// <summary>

27

/// Instance variable <c>y</c> represents the Point's y-coordinate.

28

/// </summary>

29

private int y;

30

/// <value>

31

///

The Point's x-coordinate.

32

/// </value>

33

public int X

34

{

 

35

get { return x; }

36

set { x = value; }

37

}

 

38

/// <value>

39

///

The Point's y-coordinate.

40

/// </value>

41

public int Y

42

{

 

43

get { return y; }

44

set { y = value; }

45

}

 

46

/// <summary>

47

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

48

/// </summary>

49

public Point(): this(0,0) {}

50

/// <summary>

51

/// This constructor initializes the new Point to

52

///

(<paramref name="xor"/>,<paramref name="yor"/>).

53

/// </summary>

54

/// <param name="xor">The new Point's x-coordinate.</param>

55

/// <param name="yor">The new Point's y-coordinate.</param>

56

public Point(int xor, int yor) {

57

x = xor;

58

y = yor;

59

}

 

523

 

C# LANGUAGE SPECIFICATION

1

/// <summary>

2

/// This method changes the point's location to the given

3

///

coordinates.

4

/// </summary>

5

/// <param name="xor">The new x-coordinate.</param>

6

/// <param name="yor">The new y-coordinate.</param>

7

/// <seealso cref="Translate"/>

8

public void Move(int xor, int yor) {

9

x = xor;

10

y = yor;

11

}

 

12

/// <summary>

13

/// This method changes the point's location by the given

14

///

x- and y-offsets.

15

/// </summary>

16

/// <example>

17

///

The following code:

18

///

<code>

19

///

Point p = new Point(3,5);

20

///

p.Translate(-1,3);

21

///

</code>

22

/// results in <c>p</c>'s having the value (2,8).

23

/// </example>

24

/// <param name="xor">The relative x-offset.</param>

25

/// <param name="yor">The relative y-offset.</param>

26

/// <seealso cref="Move"/>

27

public void Translate(int xor, int yor) {

28

x += xor;

29

y += yor;

30

}

 

31

/// <summary>

32

/// This method determines whether two Points have the same

33

///

location.

34

/// </summary>

35

/// <param name="o">

36

/// The object to be compared to the current object.

37

/// </param>

38

/// <returns>

39

/// True if the Points have the same location; otherwise, false.

40

/// </returns>

41

/// <seealso cref="operator =="/>

42

/// <seealso cref="operator !="/>

43

public override bool Equals(object o) {

44

Point p = o as Point;

45

if (p == null) return false;

46

return x == p.x && y == p.y;

47

}

 

48

/// <summary>

49

/// Computes the hash code for a Point.

50

/// </summary>

51

/// <returns>

52

/// A hash code computed from the x and y coordinates.

53

/// </returns>

54

public override int GetHashCode() {

55

return x ^ y;

56

}

 

57

/// <summary>

58

/// Report a point's location as a string.

59

/// </summary>

60

/// <returns>

61

/// A string representing a point's location, in the form (x,y),

62

/// without any leading, training, or embedded whitespace.

63

/// </returns>

64

public override string ToString() {

65

return "(" + x + "," + y + ")";

66

}

 

524

 

 

Annex E Documentation Comments

1

/// <summary>

2

/// This operator determines whether two Points have the same

3

///

location.

4

/// </summary>

5

/// <param name="p1">The first Point to be compared.</param>

6

/// <param name="p2">The second Point to be compared.</param>

7

/// <returns>

8

/// True if the Points have the same location; otherwise, false.

9

/// </returns>

10

/// <seealso cref="Equals"/>

11

/// <seealso cref="operator !="/>

12

public static bool operator ==(Point p1, Point p2) {

13

if ((object)p1 == null || (object)p2 == null) return false;

14

return p1.x == p2.x && p1.y == p2.y;

15

}

 

16

/// <summary>

17

/// This operator determines whether two Points have the same

18

///

location.

19

/// </summary>

20

/// <param name="p1">The first Point to be compared.</param>

21

/// <param name="p2">The second Point to be compared.</param>

22

/// <returns>

23

/// True if the Points do not have the same location;

24

///

otherwise, false.

25

/// </returns>

26

/// <seealso cref="Equals"/>

27

/// <seealso cref="operator =="/>

28

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

29

return !(p1 == p2);

30

}

 

31

/// <summary>

32

///

<para>

33

///

This is the entry point of the Point class testing program.

34

///

</para>

35

///

<para>

36

///

This program tests each method and operator, and is intended

37

///

to be run after any non-trvial maintenance has been performed

38

///

on the Point class.

39

///

</para>

40

/// </summary>

41

public static void Main() {

42

// class test code goes here

43}

44}

45}

46E.4.2 Resulting XML

47Here is the output produced by one documentation generator when given the source code for class Point,

48shown above:

49<?xml version="1.0"?>

50<doc>

51<assembly>

52<name>Point</name>

53</assembly>

54<members>

55<member name="T:Graphics.Point">

56<remarks>

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

58</remarks>

59</member>

60<member name="F:Graphics.Point.x">

61<summary>

62Instance variable <c>x</c> represents the Point's x-coordinate.

63</summary>

64</member>

65<member name="F:Graphics.Point.y">

525

C# LANGUAGE SPECIFICATION

1<summary>

2Instance variable <c>y</c> represents the Point's y-coordinate.

3</summary>

4</member>

5<member name="M:Graphics.Point.#ctor">

6<summary>

7This constructor initializes the new Point to (0,0).

8</summary>

9</member>

10<member name="M:Graphics.Point.#ctor(System.Int32,System.Int32)">

11<summary>

12This constructor initializes the new Point to

13(<paramref name="xor"/>,<paramref name="yor"/>).

14</summary>

15<param name="xor">The new Point's x-coordinate.</param>

16<param name="yor">The new Point's y-coordinate.</param>

17</member>

18<member name="M:Graphics.Point.Move(System.Int32,System.Int32)">

19<summary>

20This method changes the point's location to the given

21coordinates.

22</summary>

23<param name="xor">The new x-coordinate.</param>

24<param name="yor">The new y-coordinate.</param>

25<seealso cref="M:Graphics.Point.Translate(System.Int32,System.Int32)"/>

26</member>

27<member name="M:Graphics.Point.Translate(System.Int32,System.Int32)">

28<summary>

29This method changes the point's location by the given

30x- and y-offsets.

31</summary>

32<example>

33The following code:

34<code>

35

Point p = new Point(3,5);

36

p.Translate(-1,3);

37</code>

38results in <c>p</c>'s having the value (2,8).

39</example>

40<param name="xor">The relative x-offset.</param>

41<param name="yor">The relative y-offset.</param>

42<seealso cref="M:Graphics.Point.Move(System.Int32,System.Int32)"/>

43</member>

44<member name="M:Graphics.Point.Equals(System.Object)">

45<summary>

46This method determines whether two Points have the same

47location.

48</summary>

49<param name="o">

50The object to be compared to the current object.

51</param>

52<returns>

53True if the Points have the same location; otherwise, false.

54</returns>

55<seealso

56cref="M:Graphics.Point.op_Equality(Graphics.Point,Graphics.Point)"/>

57<seealso

58cref="M:Graphics.Point.op_Inequality(Graphics.Point,Graphics.Point)"/>

59</member>

60<member name="M:Graphics.Point.GetHashCode">

61<summary>

62Computes the hash code for a Point.

63</summary>

64<returns>

65A hash code computed from the x and y coordinates.

66</returns>

67</member>

68<member name="M:Graphics.Point.ToString">

69<summary>

526

Annex E Documentation Comments

1Report a point's location as a string.

2</summary>

3<returns>

4A string representing a point's location, in the form (x,y),

5without any leading, training, or embedded whitespace.

6</returns>

7</member>

8<member name="M:Graphics.Point.op_Equality(Graphics.Point,Graphics.Point)">

9<summary>

10This operator determines whether two Points have the same

11location.

12</summary>

13<param name="p1">The first Point to be compared.</param>

14<param name="p2">The second Point to be compared.</param>

15<returns>

16True if the Points have the same location; otherwise, false.

17</returns>

18<seealso cref="M:Graphics.Point.Equals(System.Object)"/>

19<seealso

20cref="M:Graphics.Point.op_Inequality(Graphics.Point,Graphics.Point)"/>

21</member>

22<member

23name="M:Graphics.Point.op_Inequality(Graphics.Point,Graphics.Point)">

24<summary>

25This operator determines whether two Points have the same

26location.

27</summary>

28<param name="p1">The first Point to be compared.</param>

29<param name="p2">The second Point to be compared.</param>

30<returns>

31True if the Points do not have the same location;

32otherwise, false.

33</returns>

34<seealso cref="M:Graphics.Point.Equals(System.Object)"/>

35<seealso

36cref="M:Graphics.Point.op_Equality(Graphics.Point,Graphics.Point)"/>

37</member>

38<member name="M:Graphics.Point.Main">

39<summary>

40<para>

41

This is the entry point of the Point class testing program.

42</para>

43<para>

44

This program tests each method and operator, and is intended

45

to be run after any non-trvial maintenance has been performed

46

on the Point class.

47</para>

48</summary>

49</member>

50<member name="P:Graphics.Point.X">

51<value>

52The Point's x-coordinate.

53</value>

54</member>

55<member name="P:Graphics.Point.Y">

56<value>

57The Point's y-coordinate.

58</value>

59</member>

60</members>

61</doc>

62

63 End of informative text.

527

1Annex F. Bibliography

2This annex is informative.

3

4ANSI X3.274-1996, Programming Language REXX. (This document is useful in understanding floating-

5point decimal arithmetic rules.)

6ISO 31-0:1992, Annex B (informative), Guide to the rounding of numbers (This document defines “banker’s

7rounding.”)

8ISO/IEC 9899:1999, Programming languages — C.

9ISO/IEC 14882:1998, Programming languages — C++.

10

11 End of informative text.

528

Соседние файлы в предмете Электротехника