2 // Mono.Data.TdsTypes.TdsInt16
5 // Tim Coleman <tim@timcoleman.com>
7 // (C) Copyright Tim Coleman, 2002
10 using Mono.Data.TdsClient;
12 using System.Data.SqlTypes;
13 using System.Globalization;
15 namespace Mono.Data.TdsTypes {
16 public struct TdsInt16 : INullable, IComparable
23 public static readonly TdsInt16 MaxValue = new TdsInt16 (32767);
24 public static readonly TdsInt16 MinValue = new TdsInt16 (-32768);
25 public static readonly TdsInt16 Null;
26 public static readonly TdsInt16 Zero = new TdsInt16 (0);
32 public TdsInt16 (short value)
43 get { return !notNull; }
49 throw new TdsNullValueException ();
59 public static TdsInt16 Add (TdsInt16 x, TdsInt16 y)
64 public static TdsInt16 BitwiseAnd (TdsInt16 x, TdsInt16 y)
69 public static TdsInt16 BitwiseOr (TdsInt16 x, TdsInt16 y)
74 public int CompareTo (object value)
78 else if (!(value is TdsInt16))
79 throw new ArgumentException (Locale.GetText ("Value is not a System.Data.TdsTypes.TdsInt16"));
80 else if (((TdsInt16)value).IsNull)
83 return this.value.CompareTo (((TdsInt16)value).Value);
86 public static TdsInt16 Divide (TdsInt16 x, TdsInt16 y)
91 public override bool Equals (object value)
93 if (!(value is TdsInt16))
96 return (bool) (this == (TdsInt16)value);
99 public static TdsBoolean Equals (TdsInt16 x, TdsInt16 y)
104 public override int GetHashCode ()
109 public static TdsBoolean GreaterThan (TdsInt16 x, TdsInt16 y)
114 public static TdsBoolean GreaterThanOrEqual (TdsInt16 x, TdsInt16 y)
119 public static TdsBoolean LessThan (TdsInt16 x, TdsInt16 y)
124 public static TdsBoolean LessThanOrEqual (TdsInt16 x, TdsInt16 y)
129 public static TdsInt16 Mod (TdsInt16 x, TdsInt16 y)
134 public static TdsInt16 Multiply (TdsInt16 x, TdsInt16 y)
139 public static TdsBoolean NotEquals (TdsInt16 x, TdsInt16 y)
144 public static TdsInt16 OnesComplement (TdsInt16 x)
149 public static TdsInt16 Parse (string s)
151 return new TdsInt16 (Int16.Parse (s));
154 public static TdsInt16 Subtract (TdsInt16 x, TdsInt16 y)
159 public TdsBoolean ToTdsBoolean ()
161 return ((TdsBoolean)this);
164 public TdsByte ToTdsByte ()
166 return ((TdsByte)this);
169 public TdsDecimal ToTdsDecimal ()
171 return ((TdsDecimal)this);
174 public TdsDouble ToTdsDouble ()
176 return ((TdsDouble)this);
179 public TdsInt32 ToTdsInt32 ()
181 return ((TdsInt32)this);
184 public TdsInt64 ToTdsInt64 ()
186 return ((TdsInt64)this);
189 public TdsMoney ToTdsMoney ()
191 return ((TdsMoney)this);
194 public TdsSingle ToTdsSingle ()
196 return ((TdsSingle)this);
199 public TdsString ToTdsString ()
201 return ((TdsString)this);
204 public override string ToString ()
209 return value.ToString ();
212 public static TdsInt16 Xor (TdsInt16 x, TdsInt16 y)
217 public static TdsInt16 operator + (TdsInt16 x, TdsInt16 y)
219 return new TdsInt16 ((short) (x.Value + y.Value));
222 public static TdsInt16 operator & (TdsInt16 x, TdsInt16 y)
224 return new TdsInt16 ((short) (x.value & y.Value));
227 public static TdsInt16 operator | (TdsInt16 x, TdsInt16 y)
229 return new TdsInt16 ((short) ((byte) x.Value | (byte) y.Value));
232 public static TdsInt16 operator / (TdsInt16 x, TdsInt16 y)
234 return new TdsInt16 ((short) (x.Value / y.Value));
237 public static TdsBoolean operator == (TdsInt16 x, TdsInt16 y)
239 if (x.IsNull || y.IsNull)
240 return TdsBoolean.Null;
242 return new TdsBoolean (x.Value == y.Value);
245 public static TdsInt16 operator ^ (TdsInt16 x, TdsInt16 y)
247 return new TdsInt16 ((short) (x.Value ^ y.Value));
250 public static TdsBoolean operator > (TdsInt16 x, TdsInt16 y)
252 if (x.IsNull || y.IsNull)
253 return TdsBoolean.Null;
255 return new TdsBoolean (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 TdsBoolean operator != (TdsInt16 x, TdsInt16 y)
268 if (x.IsNull || y.IsNull)
269 return TdsBoolean.Null;
271 return new TdsBoolean (!(x.Value == y.Value));
274 public static TdsBoolean operator < (TdsInt16 x, TdsInt16 y)
276 if (x.IsNull || y.IsNull)
277 return TdsBoolean.Null;
279 return new TdsBoolean (x.Value < y.Value);
282 public static TdsBoolean operator <= (TdsInt16 x, TdsInt16 y)
284 if (x.IsNull || y.IsNull)
285 return TdsBoolean.Null;
287 return new TdsBoolean (x.Value <= y.Value);
290 public static TdsInt16 operator % (TdsInt16 x, TdsInt16 y)
292 return new TdsInt16 ((short) (x.Value % y.Value));
295 public static TdsInt16 operator * (TdsInt16 x, TdsInt16 y)
297 return new TdsInt16 ((short) (x.Value * y.Value));
300 public static TdsInt16 operator ~ (TdsInt16 x)
302 return new TdsInt16 ((short) (~x.Value));
305 public static TdsInt16 operator - (TdsInt16 x, TdsInt16 y)
307 return new TdsInt16 ((short) (x.Value - y.Value));
310 public static TdsInt16 operator - (TdsInt16 n)
312 return new TdsInt16 ((short) (-n.Value));
315 public static explicit operator TdsInt16 (TdsBoolean x)
320 return new TdsInt16 ((short)x.ByteValue);
323 public static explicit operator TdsInt16 (TdsDecimal x)
328 return new TdsInt16 ((short)x.Value);
331 public static explicit operator TdsInt16 (TdsDouble x)
336 return new TdsInt16 ((short)x.Value);
339 public static explicit operator short (TdsInt16 x)
344 public static explicit operator TdsInt16 (TdsInt32 x)
349 return new TdsInt16 ((short)x.Value);
352 public static explicit operator TdsInt16 (TdsInt64 x)
357 return new TdsInt16 ((short)x.Value);
360 public static explicit operator TdsInt16 (TdsMoney x)
365 return new TdsInt16 ((short)x.Value);
368 public static explicit operator TdsInt16 (TdsSingle x)
373 return new TdsInt16 ((short)x.Value);
376 public static explicit operator TdsInt16 (TdsString x)
378 return TdsInt16.Parse (x.Value);
381 public static implicit operator TdsInt16 (short x)
383 return new TdsInt16 (x);
386 public static implicit operator TdsInt16 (TdsByte x)
391 return new TdsInt16 ((short)x.Value);