2 // Mono.Data.TdsTypes.TdsByte
5 // Tim Coleman <tim@timcoleman.com>
7 // (C) Copyright Tim Coleman, 2002
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using Mono
.Data
.TdsClient
;
33 using System
.Data
.SqlTypes
;
34 using System
.Globalization
;
36 namespace Mono
.Data
.TdsTypes
{
37 public struct TdsByte
: INullable
, IComparable
44 public static readonly TdsByte MaxValue
= new TdsByte (0xff);
45 public static readonly TdsByte MinValue
= new TdsByte (0);
46 public static readonly TdsByte Null
;
47 public static readonly TdsByte Zero
= new TdsByte (0);
53 public TdsByte (byte value)
64 get { return !notNull; }
70 throw new TdsNullValueException ();
80 public static TdsByte
Add (TdsByte x
, TdsByte y
)
85 public static TdsByte
BitwiseAnd (TdsByte x
, TdsByte y
)
90 public static TdsByte
BitwiseOr (TdsByte x
, TdsByte y
)
95 public int CompareTo (object value)
99 else if (!(value is TdsByte
))
100 throw new ArgumentException (Locale
.GetText ("Value is not a System.Data.TdsTypes.TdsByte"));
101 else if (((TdsByte
)value).IsNull
)
104 return this.value.CompareTo (((TdsByte
)value).Value
);
107 public static TdsByte
Divide (TdsByte x
, TdsByte y
)
112 public override bool Equals (object value)
114 if (!(value is TdsByte
))
117 return (bool) (this == (TdsByte
)value);
120 public static TdsBoolean
Equals (TdsByte x
, TdsByte y
)
125 public override int GetHashCode ()
130 public static TdsBoolean
GreaterThan (TdsByte x
, TdsByte y
)
135 public static TdsBoolean
GreaterThanOrEqual (TdsByte x
, TdsByte y
)
140 public static TdsBoolean
LessThan (TdsByte x
, TdsByte y
)
145 public static TdsBoolean
LessThanOrEqual (TdsByte x
, TdsByte y
)
150 public static TdsByte
Mod (TdsByte x
, TdsByte y
)
155 public static TdsByte
Multiply (TdsByte x
, TdsByte y
)
160 public static TdsBoolean
NotEquals (TdsByte x
, TdsByte y
)
165 public static TdsByte
OnesComplement (TdsByte x
)
170 public static TdsByte
Parse (string s
)
172 return new TdsByte (Byte
.Parse (s
));
175 public static TdsByte
Subtract (TdsByte x
, TdsByte y
)
180 public TdsBoolean
ToTdsBoolean ()
182 return ((TdsBoolean
)this);
185 public TdsDecimal
ToTdsDecimal ()
187 return ((TdsDecimal
)this);
190 public TdsDouble
ToTdsDouble ()
192 return ((TdsDouble
)this);
195 public TdsInt16
ToTdsInt16 ()
197 return ((TdsInt16
)this);
200 public TdsInt32
ToTdsInt32 ()
202 return ((TdsInt32
)this);
205 public TdsInt64
ToTdsInt64 ()
207 return ((TdsInt64
)this);
210 public TdsMoney
ToTdsMoney ()
212 return ((TdsMoney
)this);
215 public TdsSingle
ToTdsSingle ()
217 return ((TdsSingle
)this);
220 public TdsString
ToTdsString ()
222 return ((TdsString
)this);
225 public override string ToString ()
230 return value.ToString ();
233 public static TdsByte
Xor (TdsByte x
, TdsByte y
)
238 public static TdsByte
operator + (TdsByte x
, TdsByte y
)
240 return new TdsByte ((byte) (x
.Value
+ y
.Value
));
243 public static TdsByte
operator & (TdsByte x
, TdsByte y
)
245 return new TdsByte ((byte) (x
.Value
& y
.Value
));
248 public static TdsByte
operator | (TdsByte x
, TdsByte y
)
250 return new TdsByte ((byte) (x
.Value
| y
.Value
));
253 public static TdsByte
operator / (TdsByte x
, TdsByte y
)
255 return new TdsByte ((byte) (x
.Value
/ y
.Value
));
258 public static TdsBoolean
operator == (TdsByte x
, TdsByte y
)
260 if (x
.IsNull
|| y
.IsNull
)
261 return TdsBoolean
.Null
;
263 return new TdsBoolean (x
.Value
== y
.Value
);
266 public static TdsByte
operator ^
(TdsByte x
, TdsByte y
)
268 return new TdsByte ((byte) (x
.Value ^ y
.Value
));
271 public static TdsBoolean
operator > (TdsByte x
, TdsByte y
)
273 if (x
.IsNull
|| y
.IsNull
)
274 return TdsBoolean
.Null
;
276 return new TdsBoolean (x
.Value
> y
.Value
);
279 public static TdsBoolean
operator >= (TdsByte x
, TdsByte y
)
281 if (x
.IsNull
|| y
.IsNull
)
282 return TdsBoolean
.Null
;
284 return new TdsBoolean (x
.Value
>= y
.Value
);
287 public static TdsBoolean
operator != (TdsByte x
, TdsByte y
)
289 if (x
.IsNull
|| y
.IsNull
)
290 return TdsBoolean
.Null
;
292 return new TdsBoolean (!(x
.Value
== y
.Value
));
295 public static TdsBoolean
operator < (TdsByte x
, TdsByte y
)
297 if (x
.IsNull
|| y
.IsNull
)
298 return TdsBoolean
.Null
;
300 return new TdsBoolean (x
.Value
< y
.Value
);
303 public static TdsBoolean
operator <= (TdsByte x
, TdsByte y
)
305 if (x
.IsNull
|| y
.IsNull
)
306 return TdsBoolean
.Null
;
308 return new TdsBoolean (x
.Value
<= y
.Value
);
311 public static TdsByte
operator % (TdsByte x
, TdsByte y
)
313 return new TdsByte ((byte) (x
.Value
% y
.Value
));
316 public static TdsByte
operator * (TdsByte x
, TdsByte y
)
318 return new TdsByte ((byte) (x
.Value
* y
.Value
));
321 public static TdsByte
operator ~
(TdsByte x
)
323 return new TdsByte ((byte) ~x
.Value
);
326 public static TdsByte
operator - (TdsByte x
, TdsByte y
)
328 return new TdsByte ((byte) (x
.Value
- y
.Value
));
331 public static explicit operator TdsByte (TdsBoolean x
)
336 return new TdsByte (x
.ByteValue
);
339 public static explicit operator byte (TdsByte x
)
344 public static explicit operator TdsByte (TdsDecimal x
)
349 return new TdsByte ((byte)x
.Value
);
352 public static explicit operator TdsByte (TdsDouble x
)
357 return new TdsByte ((byte)x
.Value
);
360 public static explicit operator TdsByte (TdsInt16 x
)
365 return new TdsByte ((byte)x
.Value
);
368 public static explicit operator TdsByte (TdsInt32 x
)
373 return new TdsByte ((byte)x
.Value
);
376 public static explicit operator TdsByte (TdsInt64 x
)
381 return new TdsByte ((byte)x
.Value
);
384 public static explicit operator TdsByte (TdsMoney x
)
389 return new TdsByte ((byte)x
.Value
);
392 public static explicit operator TdsByte (TdsSingle x
)
397 return new TdsByte ((byte)x
.Value
);
401 public static explicit operator TdsByte (TdsString x
)
403 return TdsByte
.Parse (x
.Value
);
406 public static implicit operator TdsByte (byte x
)
408 return new TdsByte (x
);