LinkArea.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //
  2. // System.Drawing.LinkArea.cs
  3. //
  4. // Author:
  5. // Dennis Hayes ([email protected])
  6. //
  7. // (C) 2002 Ximian, Inc. http://www.ximian.com
  8. //
  9. using System;
  10. namespace System.Windows.Forms {
  11. [Serializable]
  12. public struct LinkArea {
  13. private int start;
  14. private int length;
  15. // -----------------------
  16. // Public Constructor
  17. // -----------------------
  18. /// <summary>
  19. ///
  20. /// </summary>
  21. ///
  22. /// <remarks>
  23. ///
  24. /// </remarks>
  25. public LinkArea (int Start, int Length)
  26. {
  27. start = Start;
  28. length = Length;
  29. }
  30. // -----------------------
  31. // Public Shared Members
  32. // -----------------------
  33. /// <summary>
  34. /// Equality Operator
  35. /// </summary>
  36. ///
  37. /// <remarks>
  38. /// Compares two LinkArea objects. The return value is
  39. /// based on the equivalence of the Start and Length properties of the two objects.
  40. /// </remarks>
  41. public static bool operator == (LinkArea la_a,
  42. LinkArea la_b) {
  43. return ((la_a.start == la_b.start) &&
  44. (la_a.length == la_b.length));
  45. }
  46. /// <summary>
  47. /// Inequality Operator
  48. /// </summary>
  49. ///
  50. /// <remarks>
  51. /// Compares two LinkArea objects. The return value is
  52. /// based on the equivalence of the Start and Length properties of the two objects.
  53. /// </remarks>
  54. public static bool operator != (LinkArea la_a,
  55. LinkArea la_b) {
  56. return ((la_a.start != la_b.start) ||
  57. (la_a.length != la_b.length));
  58. }
  59. // -----------------------
  60. // Public Instance Members
  61. // -----------------------
  62. public bool IsEmpty {
  63. get{
  64. // Start can be 0, so no way to know if it is empty.
  65. // Docs seem to say Start must/should be set before
  66. // length, os if length is valid, start must also be ok.
  67. return length!=0;
  68. }
  69. }
  70. public int Start {
  71. get{
  72. return start;
  73. }
  74. set{
  75. start = value;
  76. }
  77. }
  78. public int Length {
  79. get{
  80. return length;
  81. }
  82. set{
  83. length = value;
  84. }
  85. }
  86. /// <summary>
  87. /// Equals Method
  88. /// </summary>
  89. ///
  90. /// <remarks>
  91. /// Checks equivalence of this LinkArea and another object.
  92. /// </remarks>
  93. public override bool Equals (object obj)
  94. {
  95. if (!(obj is LinkArea))
  96. return false;
  97. return (this == (LinkArea) obj);
  98. }
  99. /// <summary>
  100. /// GetHashCode Method
  101. /// </summary>
  102. ///
  103. /// <remarks>
  104. /// Calculates a hashing value.
  105. /// </remarks>
  106. public override int GetHashCode ()
  107. {
  108. return (int)( start ^ length);
  109. }
  110. /// <summary>
  111. /// ToString Method
  112. /// </summary>
  113. ///
  114. /// <remarks>
  115. /// Formats the LinkArea as a string.
  116. /// </remarks>
  117. public override string ToString ()
  118. {
  119. return String.Format ("[{0},{1}]", start, length );
  120. }
  121. }
  122. }