2 // System.Data.SqlTypes.SqlInt16
5 // Tim Coleman <tim@timcoleman.com>
6 // Ville Palo <vi64pa@koti.soon.fi>
8 // (C) Copyright 2002 Tim Coleman
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:
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.
35 using System
.Globalization
;
37 namespace System
.Data
.SqlTypes
39 public struct SqlInt16
: INullable
, IComparable
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);
55 public SqlInt16 (short value)
66 get { return !notNull; }
72 throw new SqlNullValueException ();
82 public static SqlInt16
Add (SqlInt16 x
, SqlInt16 y
)
87 public static SqlInt16
BitwiseAnd (SqlInt16 x
, SqlInt16 y
)
92 public static SqlInt16
BitwiseOr (SqlInt16 x
, SqlInt16 y
)
97 public int CompareTo (object value)
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);
107 public int CompareTo (SqlInt16
value)
109 return CompareSqlInt16 (value);
113 private int CompareSqlInt16 (SqlInt16
value)
115 if (((SqlInt16
)value).IsNull
)
118 return this.value.CompareTo (value.Value
);
121 public static SqlInt16
Divide (SqlInt16 x
, SqlInt16 y
)
126 public override bool Equals (object value)
128 if (!(value is SqlInt16
))
130 else if (this.IsNull
&& ((SqlInt16
)value).IsNull
)
132 else if (((SqlInt16
)value).IsNull
)
135 return (bool)(this == (SqlInt16
)value);
138 public static SqlBoolean
Equals (SqlInt16 x
, SqlInt16 y
)
143 public override int GetHashCode ()
148 public static SqlBoolean
GreaterThan (SqlInt16 x
, SqlInt16 y
)
153 public static SqlBoolean
GreaterThanOrEqual (SqlInt16 x
, SqlInt16 y
)
158 public static SqlBoolean
LessThan (SqlInt16 x
, SqlInt16 y
)
163 public static SqlBoolean
LessThanOrEqual (SqlInt16 x
, SqlInt16 y
)
168 public static SqlInt16
Mod (SqlInt16 x
, SqlInt16 y
)
174 public static SqlInt16
Modulus (SqlInt16 x
, SqlInt16 y
)
181 public static SqlInt16
Multiply (SqlInt16 x
, SqlInt16 y
)
186 public static SqlBoolean
NotEquals (SqlInt16 x
, SqlInt16 y
)
191 public static SqlInt16
OnesComplement (SqlInt16 x
)
199 public static SqlInt16
Parse (string s
)
202 return new SqlInt16 (Int16
.Parse (s
));
206 public static SqlInt16
Subtract (SqlInt16 x
, SqlInt16 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 ()
261 return value.ToString ();
264 public static SqlInt16
Xor (SqlInt16 x
, SqlInt16 y
)
269 public static SqlInt16
operator + (SqlInt16 x
, SqlInt16 y
)
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
)
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
;
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
;
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
;
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
;
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
;
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
;
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
)
354 return new SqlInt16 ((short) (x
.Value
* y
.Value
));
358 public static SqlInt16
operator ~
(SqlInt16 x
)
363 return new SqlInt16 ((short) (~x
.Value
));
366 public static SqlInt16
operator - (SqlInt16 x
, SqlInt16 y
)
369 return new SqlInt16 ((short) (x
.Value
- y
.Value
));
373 public static SqlInt16
operator - (SqlInt16 n
)
376 return new SqlInt16 ((short) (-n
.Value
));
380 public static explicit operator SqlInt16 (SqlBoolean x
)
385 return new SqlInt16 ((short)x
.ByteValue
);
388 public static explicit operator SqlInt16 (SqlDecimal x
)
394 return new SqlInt16 ((short)x
.Value
);
398 public static explicit operator SqlInt16 (SqlDouble x
)
403 return new SqlInt16 (checked ((short)x
.Value
));
406 public static explicit operator short (SqlInt16 x
)
411 public static explicit operator SqlInt16 (SqlInt32 x
)
417 return new SqlInt16 ((short)x
.Value
);
421 public static explicit operator SqlInt16 (SqlInt64 x
)
427 return new SqlInt16 ((short)x
.Value
);
432 public static explicit operator SqlInt16 (SqlMoney x
)
438 return new SqlInt16 ((short) Math
.Round (x
.Value
));
443 public static explicit operator SqlInt16 (SqlSingle x
)
449 return new SqlInt16 ((short)x
.Value
);
454 public static explicit operator SqlInt16 (SqlString x
)
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
);