2 // Mono.Data.SybaseTypes.SybaseBoolean
5 // Tim Coleman (tim@timcoleman.com)
7 // Based on System.Data.SqlTypes.SqlBoolean
9 // (C) Ximian, Inc. 2002-2003
10 // (C) Copyright Tim Coleman, 2002-2003
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using Mono
.Data
.SybaseClient
;
36 using System
.Data
.SqlTypes
;
37 using System
.Globalization
;
39 namespace Mono
.Data
.SybaseTypes
{
40 public struct SybaseBoolean
: INullable
, IComparable
49 public static readonly SybaseBoolean False
= new SybaseBoolean (false);
50 public static readonly SybaseBoolean Null
;
51 public static readonly SybaseBoolean One
= new SybaseBoolean (1);
52 public static readonly SybaseBoolean True
= new SybaseBoolean (true);
53 public static readonly SybaseBoolean Zero
= new SybaseBoolean (0);
59 public SybaseBoolean (bool value)
61 this.value = (byte) (value ? 1 : 0);
65 public SybaseBoolean (int value)
67 this.value = (byte) (value != 0 ? 1 : 0);
71 #endregion // Constructors
75 public byte ByteValue
{
78 throw new SybaseNullValueException(Locale
.GetText("The property is set to null."));
111 throw new SybaseNullValueException(Locale
.GetText("The property is set to null."));
117 #endregion // Properties
119 public static SybaseBoolean
And (SybaseBoolean x
, SybaseBoolean y
)
124 public int CompareTo (object value)
128 else if (!(value is SybaseBoolean
))
129 throw new ArgumentException (Locale
.GetText ("Value is not a System.Data.SybaseTypes.SybaseBoolean"));
130 else if (((SybaseBoolean
)value).IsNull
)
133 return this.value.CompareTo (((SybaseBoolean
)value).ByteValue
);
136 public override bool Equals(object value)
138 if (!(value is SybaseByte
))
141 return (bool) (this == (SybaseBoolean
)value);
144 public static SybaseBoolean
Equals(SybaseBoolean x
, SybaseBoolean y
)
149 public override int GetHashCode()
154 public static SybaseBoolean
NotEquals(SybaseBoolean x
, SybaseBoolean y
)
159 public static SybaseBoolean
OnesComplement(SybaseBoolean x
)
164 public static SybaseBoolean
Or(SybaseBoolean x
, SybaseBoolean y
)
169 public static SybaseBoolean
Parse(string s
)
171 return new SybaseBoolean (Boolean
.Parse (s
));
174 public SybaseByte
ToSybaseByte()
176 return new SybaseByte (value);
179 // **************************************************
180 // Conversion from SybaseBoolean to other SybaseTypes
181 // **************************************************
183 public SybaseDecimal
ToSybaseDecimal()
185 return ((SybaseDecimal
)this);
188 public SybaseDouble
ToSybaseDouble()
190 return ((SybaseDouble
)this);
193 public SybaseInt16
ToSybaseInt16()
195 return ((SybaseInt16
)this);
198 public SybaseInt32
ToSybaseInt32()
200 return ((SybaseInt32
)this);
203 public SybaseInt64
ToSybaseInt64()
205 return ((SybaseInt64
)this);
208 public SybaseMoney
ToSybaseMoney()
210 return ((SybaseMoney
)this);
213 public SybaseSingle
ToSybaseSingle()
215 return ((SybaseSingle
)this);
218 public SybaseString
ToSybaseString()
221 return new SybaseString ("Null");
223 return new SybaseString ("True");
225 return new SybaseString ("False");
228 public override string ToString()
238 // Bitwise exclusive-OR (XOR)
239 public static SybaseBoolean
Xor(SybaseBoolean x
, SybaseBoolean y
)
244 // **************************************************
246 // **************************************************
249 public static SybaseBoolean
operator & (SybaseBoolean x
, SybaseBoolean y
)
251 return new SybaseBoolean (x
.Value
& y
.Value
);
255 public static SybaseBoolean
operator | (SybaseBoolean x
, SybaseBoolean y
)
257 return new SybaseBoolean (x
.Value
| y
.Value
);
261 // Compares two instances for equality
262 public static SybaseBoolean
operator == (SybaseBoolean x
, SybaseBoolean y
)
264 if (x
.IsNull
|| y
.IsNull
)
265 return SybaseBoolean
.Null
;
267 return new SybaseBoolean (x
.Value
== y
.Value
);
270 // Bitwize exclusive-OR (XOR)
271 public static SybaseBoolean
operator ^
(SybaseBoolean x
, SybaseBoolean y
)
273 return new SybaseBoolean (x
.Value ^ y
.Value
);
276 // test Value of SybaseBoolean to determine it is false.
277 public static bool operator false (SybaseBoolean x
)
283 public static SybaseBoolean
operator != (SybaseBoolean x
, SybaseBoolean y
)
285 if (x
.IsNull
|| y
.IsNull
)
286 return SybaseBoolean
.Null
;
288 return new SybaseBoolean (x
.Value
!= y
.Value
);
292 public static SybaseBoolean
operator ! (SybaseBoolean x
)
295 return SybaseBoolean
.Null
;
297 return new SybaseBoolean (!x
.Value
);
301 public static SybaseBoolean
operator ~
(SybaseBoolean x
)
303 return new SybaseBoolean (~x
.ByteValue
);
306 // test to see if value is true
307 public static bool operator true (SybaseBoolean x
)
312 // ****************************************
314 // ****************************************
317 // SybaseBoolean to Boolean
318 public static explicit operator bool (SybaseBoolean x
)
324 // SybaseByte to SybaseBoolean
325 public static explicit operator SybaseBoolean (SybaseByte x
)
330 return new SybaseBoolean ((int)x
.Value
);
333 // SybaseDecimal to SybaseBoolean
334 public static explicit operator SybaseBoolean (SybaseDecimal x
)
339 return new SybaseBoolean ((int)x
.Value
);
342 // SybaseDouble to SybaseBoolean
343 public static explicit operator SybaseBoolean (SybaseDouble x
)
348 return new SybaseBoolean ((int)x
.Value
);
351 // SybaseInt16 to SybaseBoolean
352 public static explicit operator SybaseBoolean (SybaseInt16 x
)
357 return new SybaseBoolean ((int)x
.Value
);
360 // SybaseInt32 to SybaseBoolean
361 public static explicit operator SybaseBoolean (SybaseInt32 x
)
366 return new SybaseBoolean (x
.Value
);
369 // SybaseInt64 to SybaseBoolean
370 public static explicit operator SybaseBoolean (SybaseInt64 x
)
375 return new SybaseBoolean ((int)x
.Value
);
378 // SybaseMoney to SybaseBoolean
379 public static explicit operator SybaseBoolean (SybaseMoney x
)
384 return new SybaseBoolean ((int)x
.Value
);
387 // SybaseSingle to SybaseBoolean
388 public static explicit operator SybaseBoolean (SybaseSingle x
)
393 return new SybaseBoolean ((int)x
.Value
);
396 // SybaseString to SybaseBoolean
397 public static explicit operator SybaseBoolean (SybaseString x
)
399 return SybaseBoolean
.Parse (x
.Value
);
402 // Boolean to SybaseBoolean
403 public static implicit operator SybaseBoolean (bool x
)
405 return new SybaseBoolean (x
);