**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Data.OracleClient / System.Data.OracleClient / OracleString.cs
blobdced2f4f7439685d8ba68ef5755d1cce7235db7d
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 <tim@timcoleman.com>
11 // Atsushi Enomoto <atsushi@ximian.com>
13 // Copyright (C) Tim Coleman, 2003
15 // Licensed under the MIT/X11 License.
18 using System;
19 using System.Data.SqlTypes;
20 using System.Globalization;
22 namespace System.Data.OracleClient
24 public struct OracleString : IComparable, INullable
26 #region Fields
28 string value;
29 bool notNull;
31 public static readonly OracleString Empty = new OracleString (String.Empty);
32 public static readonly OracleString Null = new OracleString ();
34 #endregion // Fields
36 #region Constructors
38 public OracleString (string s)
40 value = s;
41 notNull = true;
44 #endregion // Constructors
46 #region Properties
48 public bool IsNull {
49 get { return !notNull; }
52 public int Length {
53 get { return value.Length; }
56 public char this [int index] {
57 get { return value [index]; }
60 public string Value {
61 get { return value; }
64 #endregion // Properties
66 #region Methods
68 public int CompareTo (object value)
70 if (value == null)
71 return 1;
72 else if (!(value is OracleString))
73 throw new ArgumentException ("Value is not a System.Data.OracleClient.OracleString");
74 else if (((OracleString) value).IsNull)
75 return 1;
76 else
77 return this.value.CompareTo (((OracleString) value).Value);
80 [MonoTODO]
81 public static OracleBoolean GreaterThan (OracleString x, OracleString y)
83 throw new NotImplementedException ();
86 [MonoTODO]
87 public static OracleBoolean GreaterThanOrEqual (OracleString x, OracleString y)
89 throw new NotImplementedException ();
92 public static OracleBoolean LessThan (OracleString x, OracleString y)
94 return (x < y);
97 public static OracleBoolean LessThanOrEqual (OracleString x, OracleString y)
99 return (x <= y);
102 public static OracleString Concat (OracleString x, OracleString y)
104 return x + y;
107 public override int GetHashCode ()
109 // It returns value string's HashCode.
110 return notNull ? value.GetHashCode () : 0;
113 public override bool Equals (object o)
115 if (o is OracleString) {
116 OracleString s = (OracleString) o;
117 if (notNull && s.notNull)
118 return value == s.value;
119 else
120 throw new InvalidOperationException ("the value is Null.");
122 return false;
125 public static OracleBoolean Equals (OracleString x, OracleString y)
127 return (x == y);
130 public static OracleBoolean NotEquals (OracleString x, OracleString y)
132 return (x != y);
135 public override string ToString ()
137 return notNull ? value : "Null";
140 #endregion // Methods
142 #region Operators
144 public static OracleString operator + (OracleString x, OracleString y)
146 return (x.notNull && y.notNull) ?
147 new OracleString (x.value + y.value) :
148 Null;
151 public static OracleBoolean operator == (OracleString x, OracleString y)
153 return (!x.notNull || !y.notNull) ?
154 OracleBoolean.Null : new OracleBoolean (x.value == y.value);
157 public static explicit operator string (OracleString x)
159 return x.Value;
162 [MonoTODO]
163 public static OracleBoolean operator > (OracleString x, OracleString y)
165 throw new NotImplementedException ();
168 [MonoTODO]
169 public static OracleBoolean operator >= (OracleString x, OracleString y)
171 throw new NotImplementedException ();
174 public static implicit operator OracleString (string s)
176 return new OracleString (s);
179 public static OracleBoolean operator != (OracleString x, OracleString y)
181 return (!x.notNull || !y.notNull) ?
182 OracleBoolean.Null : x.value != y.value;
185 public static OracleBoolean operator < (OracleString x, OracleString y)
187 return (!x.notNull || !y.notNull) ?
188 OracleBoolean.Null :
189 new OracleBoolean (String.Compare (x.value, y.value, false, CultureInfo.InvariantCulture) < 0);
192 public static OracleBoolean operator <= (OracleString x, OracleString y)
194 return (!x.notNull || !y.notNull) ?
195 OracleBoolean.Null : new OracleBoolean (String.Compare (x.value, y.value, false, CultureInfo.InvariantCulture) <= 0);
198 #endregion // Operators