2 // Mono.Data.TdsTypes.TdsInt16
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 TdsInt16
: INullable
, IComparable
44 public static readonly TdsInt16 MaxValue
= new TdsInt16 (32767);
45 public static readonly TdsInt16 MinValue
= new TdsInt16 (-32768);
46 public static readonly TdsInt16 Null
;
47 public static readonly TdsInt16 Zero
= new TdsInt16 (0);
53 public TdsInt16 (short value)
64 get { return !notNull; }
70 throw new TdsNullValueException ();
80 public static TdsInt16
Add (TdsInt16 x
, TdsInt16 y
)
85 public static TdsInt16
BitwiseAnd (TdsInt16 x
, TdsInt16 y
)
90 public static TdsInt16
BitwiseOr (TdsInt16 x
, TdsInt16 y
)
95 public int CompareTo (object value)
99 else if (!(value is TdsInt16
))
100 throw new ArgumentException (Locale
.GetText ("Value is not a System.Data.TdsTypes.TdsInt16"));
101 else if (((TdsInt16
)value).IsNull
)
104 return this.value.CompareTo (((TdsInt16
)value).Value
);
107 public static TdsInt16
Divide (TdsInt16 x
, TdsInt16 y
)
112 public override bool Equals (object value)
114 if (!(value is TdsInt16
))
117 return (bool) (this == (TdsInt16
)value);
120 public static TdsBoolean
Equals (TdsInt16 x
, TdsInt16 y
)
125 public override int GetHashCode ()
130 public static TdsBoolean
GreaterThan (TdsInt16 x
, TdsInt16 y
)
135 public static TdsBoolean
GreaterThanOrEqual (TdsInt16 x
, TdsInt16 y
)
140 public static TdsBoolean
LessThan (TdsInt16 x
, TdsInt16 y
)
145 public static TdsBoolean
LessThanOrEqual (TdsInt16 x
, TdsInt16 y
)
150 public static TdsInt16
Mod (TdsInt16 x
, TdsInt16 y
)
155 public static TdsInt16
Multiply (TdsInt16 x
, TdsInt16 y
)
160 public static TdsBoolean
NotEquals (TdsInt16 x
, TdsInt16 y
)
165 public static TdsInt16
OnesComplement (TdsInt16 x
)
170 public static TdsInt16
Parse (string s
)
172 return new TdsInt16 (Int16
.Parse (s
));
175 public static TdsInt16
Subtract (TdsInt16 x
, TdsInt16 y
)
180 public TdsBoolean
ToTdsBoolean ()
182 return ((TdsBoolean
)this);
185 public TdsByte
ToTdsByte ()
187 return ((TdsByte
)this);
190 public TdsDecimal
ToTdsDecimal ()
192 return ((TdsDecimal
)this);
195 public TdsDouble
ToTdsDouble ()
197 return ((TdsDouble
)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 TdsInt16
Xor (TdsInt16 x
, TdsInt16 y
)
238 public static TdsInt16
operator + (TdsInt16 x
, TdsInt16 y
)
240 return new TdsInt16 ((short) (x
.Value
+ y
.Value
));
243 public static TdsInt16
operator & (TdsInt16 x
, TdsInt16 y
)
245 return new TdsInt16 ((short) (x
.value & y
.Value
));
248 public static TdsInt16
operator | (TdsInt16 x
, TdsInt16 y
)
250 return new TdsInt16 ((short) ((byte) x
.Value
| (byte) y
.Value
));
253 public static TdsInt16
operator / (TdsInt16 x
, TdsInt16 y
)
255 return new TdsInt16 ((short) (x
.Value
/ y
.Value
));
258 public static TdsBoolean
operator == (TdsInt16 x
, TdsInt16 y
)
260 if (x
.IsNull
|| y
.IsNull
)
261 return TdsBoolean
.Null
;
263 return new TdsBoolean (x
.Value
== y
.Value
);
266 public static TdsInt16
operator ^
(TdsInt16 x
, TdsInt16 y
)
268 return new TdsInt16 ((short) (x
.Value ^ y
.Value
));
271 public static TdsBoolean
operator > (TdsInt16 x
, TdsInt16 y
)
273 if (x
.IsNull
|| y
.IsNull
)
274 return TdsBoolean
.Null
;
276 return new TdsBoolean (x
.Value
> y
.Value
);
279 public static TdsBoolean
operator >= (TdsInt16 x
, TdsInt16 y
)
281 if (x
.IsNull
|| y
.IsNull
)
282 return TdsBoolean
.Null
;
284 return new TdsBoolean (x
.Value
>= y
.Value
);
287 public static TdsBoolean
operator != (TdsInt16 x
, TdsInt16 y
)
289 if (x
.IsNull
|| y
.IsNull
)
290 return TdsBoolean
.Null
;
292 return new TdsBoolean (!(x
.Value
== y
.Value
));
295 public static TdsBoolean
operator < (TdsInt16 x
, TdsInt16 y
)
297 if (x
.IsNull
|| y
.IsNull
)
298 return TdsBoolean
.Null
;
300 return new TdsBoolean (x
.Value
< y
.Value
);
303 public static TdsBoolean
operator <= (TdsInt16 x
, TdsInt16 y
)
305 if (x
.IsNull
|| y
.IsNull
)
306 return TdsBoolean
.Null
;
308 return new TdsBoolean (x
.Value
<= y
.Value
);
311 public static TdsInt16
operator % (TdsInt16 x
, TdsInt16 y
)
313 return new TdsInt16 ((short) (x
.Value
% y
.Value
));
316 public static TdsInt16
operator * (TdsInt16 x
, TdsInt16 y
)
318 return new TdsInt16 ((short) (x
.Value
* y
.Value
));
321 public static TdsInt16
operator ~
(TdsInt16 x
)
323 return new TdsInt16 ((short) (~x
.Value
));
326 public static TdsInt16
operator - (TdsInt16 x
, TdsInt16 y
)
328 return new TdsInt16 ((short) (x
.Value
- y
.Value
));
331 public static TdsInt16
operator - (TdsInt16 n
)
333 return new TdsInt16 ((short) (-n
.Value
));
336 public static explicit operator TdsInt16 (TdsBoolean x
)
341 return new TdsInt16 ((short)x
.ByteValue
);
344 public static explicit operator TdsInt16 (TdsDecimal x
)
349 return new TdsInt16 ((short)x
.Value
);
352 public static explicit operator TdsInt16 (TdsDouble x
)
357 return new TdsInt16 ((short)x
.Value
);
360 public static explicit operator short (TdsInt16 x
)
365 public static explicit operator TdsInt16 (TdsInt32 x
)
370 return new TdsInt16 ((short)x
.Value
);
373 public static explicit operator TdsInt16 (TdsInt64 x
)
378 return new TdsInt16 ((short)x
.Value
);
381 public static explicit operator TdsInt16 (TdsMoney x
)
386 return new TdsInt16 ((short)x
.Value
);
389 public static explicit operator TdsInt16 (TdsSingle x
)
394 return new TdsInt16 ((short)x
.Value
);
397 public static explicit operator TdsInt16 (TdsString x
)
399 return TdsInt16
.Parse (x
.Value
);
402 public static implicit operator TdsInt16 (short x
)
404 return new TdsInt16 (x
);
407 public static implicit operator TdsInt16 (TdsByte x
)
412 return new TdsInt16 ((short)x
.Value
);