(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Data / System.Data.SqlTypes / SqlInt16.cs
blob1d4084eaf20be9078a133bfd9003f05c03174bb7
1 //
2 // System.Data.SqlTypes.SqlInt16
3 //
4 // Author:
5 // Tim Coleman <tim@timcoleman.com>
6 // Ville Palo <vi64pa@koti.soon.fi>
7 //
8 // (C) Copyright 2002 Tim Coleman
9 //
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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:
21 //
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 //
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 System;
35 using System.Globalization;
37 namespace System.Data.SqlTypes
39 public struct SqlInt16 : INullable, IComparable
41 #region Fields
43 short value;
44 private bool notNull;
46 public static readonly SqlInt16 MaxValue = new SqlInt16 (32767);
47 public static readonly SqlInt16 MinValue = new SqlInt16 (-32768);
48 public static readonly SqlInt16 Null;
49 public static readonly SqlInt16 Zero = new SqlInt16 (0);
51 #endregion
53 #region Constructors
55 public SqlInt16 (short value)
57 this.value = value;
58 notNull = true;;
61 #endregion
63 #region Properties
65 public bool IsNull {
66 get { return !notNull; }
69 public short Value {
70 get {
71 if (this.IsNull)
72 throw new SqlNullValueException ();
73 else
74 return value;
78 #endregion
80 #region Methods
82 public static SqlInt16 Add (SqlInt16 x, SqlInt16 y)
84 return (x + y);
87 public static SqlInt16 BitwiseAnd (SqlInt16 x, SqlInt16 y)
89 return (x & y);
92 public static SqlInt16 BitwiseOr (SqlInt16 x, SqlInt16 y)
94 return (x | y);
97 public int CompareTo (object value)
99 if (value == null)
100 return 1;
101 else if (!(value is SqlInt16))
102 throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SqlTypes.SqlInt16"));
103 return CompareSqlInt16 ((SqlInt16) value);
106 #if NET_2_0
107 public int CompareTo (SqlInt16 value)
109 return CompareSqlInt16 (value);
111 #endif
113 private int CompareSqlInt16 (SqlInt16 value)
115 if (((SqlInt16)value).IsNull)
116 return 1;
117 else
118 return this.value.CompareTo (value.Value);
121 public static SqlInt16 Divide (SqlInt16 x, SqlInt16 y)
123 return (x / y);
126 public override bool Equals (object value)
128 if (!(value is SqlInt16))
129 return false;
130 else if (this.IsNull && ((SqlInt16)value).IsNull)
131 return true;
132 else if (((SqlInt16)value).IsNull)
133 return false;
134 else
135 return (bool)(this == (SqlInt16)value);
138 public static SqlBoolean Equals (SqlInt16 x, SqlInt16 y)
140 return (x == y);
143 public override int GetHashCode ()
145 return (int)value;
148 public static SqlBoolean GreaterThan (SqlInt16 x, SqlInt16 y)
150 return (x > y);
153 public static SqlBoolean GreaterThanOrEqual (SqlInt16 x, SqlInt16 y)
155 return (x >= y);
158 public static SqlBoolean LessThan (SqlInt16 x, SqlInt16 y)
160 return (x < y);
163 public static SqlBoolean LessThanOrEqual (SqlInt16 x, SqlInt16 y)
165 return (x <= y);
168 public static SqlInt16 Mod (SqlInt16 x, SqlInt16 y)
170 return (x % y);
173 #if NET_2_0
174 public static SqlInt16 Modulus (SqlInt16 x, SqlInt16 y)
176 return (x % y);
178 #endif
181 public static SqlInt16 Multiply (SqlInt16 x, SqlInt16 y)
183 return (x * y);
186 public static SqlBoolean NotEquals (SqlInt16 x, SqlInt16 y)
188 return (x != y);
191 public static SqlInt16 OnesComplement (SqlInt16 x)
193 if (x.IsNull)
194 return Null;
196 return ~x;
199 public static SqlInt16 Parse (string s)
201 checked {
202 return new SqlInt16 (Int16.Parse (s));
206 public static SqlInt16 Subtract (SqlInt16 x, SqlInt16 y)
208 return (x - y);
211 public SqlBoolean ToSqlBoolean ()
213 return ((SqlBoolean)this);
216 public SqlByte ToSqlByte ()
218 return ((SqlByte)this);
221 public SqlDecimal ToSqlDecimal ()
223 return ((SqlDecimal)this);
226 public SqlDouble ToSqlDouble ()
228 return ((SqlDouble)this);
231 public SqlInt32 ToSqlInt32 ()
233 return ((SqlInt32)this);
236 public SqlInt64 ToSqlInt64 ()
238 return ((SqlInt64)this);
241 public SqlMoney ToSqlMoney ()
243 return ((SqlMoney)this);
246 public SqlSingle ToSqlSingle ()
248 return ((SqlSingle)this);
251 public SqlString ToSqlString ()
253 return ((SqlString)this);
256 public override string ToString ()
258 if (this.IsNull)
259 return "Null";
260 else
261 return value.ToString ();
264 public static SqlInt16 Xor (SqlInt16 x, SqlInt16 y)
266 return (x ^ y);
269 public static SqlInt16 operator + (SqlInt16 x, SqlInt16 y)
271 checked {
272 return new SqlInt16 ((short) (x.Value + y.Value));
276 public static SqlInt16 operator & (SqlInt16 x, SqlInt16 y)
278 return new SqlInt16 ((short) (x.value & y.Value));
281 public static SqlInt16 operator | (SqlInt16 x, SqlInt16 y)
283 return new SqlInt16 ((short) ( x.Value | y.Value));
286 public static SqlInt16 operator / (SqlInt16 x, SqlInt16 y)
288 checked {
289 return new SqlInt16 ((short) (x.Value / y.Value));
293 public static SqlBoolean operator == (SqlInt16 x, SqlInt16 y)
295 if (x.IsNull || y.IsNull)
296 return SqlBoolean.Null;
297 else
298 return new SqlBoolean (x.Value == y.Value);
301 public static SqlInt16 operator ^ (SqlInt16 x, SqlInt16 y)
303 return new SqlInt16 ((short) (x.Value ^ y.Value));
306 public static SqlBoolean operator > (SqlInt16 x, SqlInt16 y)
308 if (x.IsNull || y.IsNull)
309 return SqlBoolean.Null;
310 else
311 return new SqlBoolean (x.Value > y.Value);
314 public static SqlBoolean operator >= (SqlInt16 x, SqlInt16 y)
316 if (x.IsNull || y.IsNull)
317 return SqlBoolean.Null;
318 else
319 return new SqlBoolean (x.Value >= y.Value);
322 public static SqlBoolean operator != (SqlInt16 x, SqlInt16 y)
324 if (x.IsNull || y.IsNull)
325 return SqlBoolean.Null;
326 else
327 return new SqlBoolean (!(x.Value == y.Value));
330 public static SqlBoolean operator < (SqlInt16 x, SqlInt16 y)
332 if (x.IsNull || y.IsNull)
333 return SqlBoolean.Null;
334 else
335 return new SqlBoolean (x.Value < y.Value);
338 public static SqlBoolean operator <= (SqlInt16 x, SqlInt16 y)
340 if (x.IsNull || y.IsNull)
341 return SqlBoolean.Null;
342 else
343 return new SqlBoolean (x.Value <= y.Value);
346 public static SqlInt16 operator % (SqlInt16 x, SqlInt16 y)
348 return new SqlInt16 ((short) (x.Value % y.Value));
351 public static SqlInt16 operator * (SqlInt16 x, SqlInt16 y)
353 checked {
354 return new SqlInt16 ((short) (x.Value * y.Value));
358 public static SqlInt16 operator ~ (SqlInt16 x)
360 if (x.IsNull)
361 return Null;
363 return new SqlInt16 ((short) (~x.Value));
366 public static SqlInt16 operator - (SqlInt16 x, SqlInt16 y)
368 checked {
369 return new SqlInt16 ((short) (x.Value - y.Value));
373 public static SqlInt16 operator - (SqlInt16 n)
375 checked {
376 return new SqlInt16 ((short) (-n.Value));
380 public static explicit operator SqlInt16 (SqlBoolean x)
382 if (x.IsNull)
383 return Null;
384 else
385 return new SqlInt16 ((short)x.ByteValue);
388 public static explicit operator SqlInt16 (SqlDecimal x)
390 checked {
391 if (x.IsNull)
392 return Null;
393 else
394 return new SqlInt16 ((short)x.Value);
398 public static explicit operator SqlInt16 (SqlDouble x)
400 if (x.IsNull)
401 return Null;
402 else
403 return new SqlInt16 (checked ((short)x.Value));
406 public static explicit operator short (SqlInt16 x)
408 return x.Value;
411 public static explicit operator SqlInt16 (SqlInt32 x)
413 checked {
414 if (x.IsNull)
415 return Null;
416 else
417 return new SqlInt16 ((short)x.Value);
421 public static explicit operator SqlInt16 (SqlInt64 x)
423 if (x.IsNull)
424 return Null;
425 else {
426 checked {
427 return new SqlInt16 ((short)x.Value);
432 public static explicit operator SqlInt16 (SqlMoney x)
434 checked {
435 if (x.IsNull)
436 return Null;
437 else
438 return new SqlInt16 ((short) Math.Round (x.Value));
443 public static explicit operator SqlInt16 (SqlSingle x)
445 if (x.IsNull)
446 return Null;
447 else {
448 checked {
449 return new SqlInt16 ((short)x.Value);
454 public static explicit operator SqlInt16 (SqlString x)
456 if (x.IsNull)
457 return Null;
459 return SqlInt16.Parse (x.Value);
462 public static implicit operator SqlInt16 (short x)
464 return new SqlInt16 (x);
467 public static implicit operator SqlInt16 (SqlByte x)
469 return new SqlInt16 ((short)x.Value);
472 #endregion