OracleString.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. //
  2. // OracleString.cs
  3. //
  4. // Part of the Mono class libraries at
  5. // mcs/class/System.Data.OracleClient/System.Data.OracleClient
  6. //
  7. // Assembly: System.Data.OracleClient.dll
  8. // Namespace: System.Data.OracleClient
  9. //
  10. // Authors: Tim Coleman <[email protected]>
  11. // Atsushi Enomoto <[email protected]>
  12. //
  13. // Copyright (C) Tim Coleman, 2003
  14. //
  15. // Licensed under the MIT/X11 License.
  16. //
  17. using System;
  18. using System.Data.SqlTypes;
  19. using System.Globalization;
  20. namespace System.Data.OracleClient
  21. {
  22. public struct OracleString : IComparable, INullable
  23. {
  24. #region Fields
  25. string value;
  26. bool notNull;
  27. public static readonly OracleString Empty = new OracleString (String.Empty);
  28. public static readonly OracleString Null = new OracleString ();
  29. #endregion // Fields
  30. #region Constructors
  31. public OracleString (string s)
  32. {
  33. value = s;
  34. notNull = true;
  35. }
  36. #endregion // Constructors
  37. #region Properties
  38. public bool IsNull {
  39. get { return !notNull; }
  40. }
  41. public int Length {
  42. get { return value.Length; }
  43. }
  44. public char this [int index] {
  45. get { return value [index]; }
  46. }
  47. public string Value {
  48. get { return value; }
  49. }
  50. #endregion // Properties
  51. #region Methods
  52. public int CompareTo (object obj)
  53. {
  54. if (obj == null)
  55. return 1;
  56. else if (!(obj is OracleString))
  57. throw new ArgumentException ("Value is not a System.Data.OracleClient.OracleString");
  58. else if (((OracleString) obj).IsNull)
  59. return 1;
  60. else
  61. return value.CompareTo (((OracleString) obj).Value);
  62. }
  63. public static OracleBoolean GreaterThan (OracleString x, OracleString y)
  64. {
  65. if (x.IsNull || y.IsNull)
  66. return OracleBoolean.Null;
  67. return (x > y);
  68. }
  69. public static OracleBoolean GreaterThanOrEqual (OracleString x, OracleString y)
  70. {
  71. if (x.IsNull || y.IsNull)
  72. return OracleBoolean.Null;
  73. return (x >= y);
  74. }
  75. public static OracleBoolean LessThan (OracleString x, OracleString y)
  76. {
  77. return (x < y);
  78. }
  79. public static OracleBoolean LessThanOrEqual (OracleString x, OracleString y)
  80. {
  81. return (x <= y);
  82. }
  83. public static OracleString Concat (OracleString x, OracleString y)
  84. {
  85. return x + y;
  86. }
  87. public override int GetHashCode ()
  88. {
  89. // It returns value string's HashCode.
  90. return notNull ? value.GetHashCode () : 0;
  91. }
  92. public override bool Equals (object value)
  93. {
  94. if (value is OracleString) {
  95. OracleString s = (OracleString) value;
  96. if (notNull && s.notNull)
  97. return this.value == s.value;
  98. else
  99. throw new InvalidOperationException ("the value is Null.");
  100. }
  101. return false;
  102. }
  103. public static OracleBoolean Equals (OracleString x, OracleString y)
  104. {
  105. return (x == y);
  106. }
  107. public static OracleBoolean NotEquals (OracleString x, OracleString y)
  108. {
  109. return (x != y);
  110. }
  111. public override string ToString ()
  112. {
  113. return notNull ? value : "Null";
  114. }
  115. #endregion // Methods
  116. #region Operators
  117. public static OracleString operator + (OracleString x, OracleString y)
  118. {
  119. return (x.notNull && y.notNull) ?
  120. new OracleString (x.value + y.value) :
  121. Null;
  122. }
  123. public static OracleBoolean operator == (OracleString x, OracleString y)
  124. {
  125. return (!x.notNull || !y.notNull) ?
  126. OracleBoolean.Null : new OracleBoolean (x.value == y.value);
  127. }
  128. public static explicit operator string (OracleString x)
  129. {
  130. return x.Value;
  131. }
  132. [MonoTODO]
  133. public static OracleBoolean operator > (OracleString x, OracleString y)
  134. {
  135. throw new NotImplementedException ();
  136. }
  137. [MonoTODO]
  138. public static OracleBoolean operator >= (OracleString x, OracleString y)
  139. {
  140. throw new NotImplementedException ();
  141. }
  142. public static implicit operator OracleString (string s)
  143. {
  144. return new OracleString (s);
  145. }
  146. public static OracleBoolean operator != (OracleString x, OracleString y)
  147. {
  148. return (!x.notNull || !y.notNull) ?
  149. OracleBoolean.Null : x.value != y.value;
  150. }
  151. public static OracleBoolean operator < (OracleString x, OracleString y)
  152. {
  153. return (!x.notNull || !y.notNull) ?
  154. OracleBoolean.Null :
  155. new OracleBoolean (String.Compare (x.value, y.value, false, CultureInfo.InvariantCulture) < 0);
  156. }
  157. public static OracleBoolean operator <= (OracleString x, OracleString y)
  158. {
  159. return (!x.notNull || !y.notNull) ?
  160. OracleBoolean.Null : new OracleBoolean (String.Compare (x.value, y.value, false, CultureInfo.InvariantCulture) <= 0);
  161. }
  162. #endregion // Operators
  163. }
  164. }