New tests, and fixed buffer mcs -> gmcs switch.
[mono.git] / mcs / class / System.Data / System.Data.SqlTypes.jvm / SqlInt16.cs
1 // System.Data.SqlTypes.SqlInt16\r
2 //
3 // Authors:
4 //      Konstantin Triger <kostat@mainsoft.com>
5 //      Boris Kirzner <borisk@mainsoft.com>
6 //      
7 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
8 //
9
10 //
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:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
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.
29 //\r
30 \r
31 namespace System.Data.SqlTypes\r
32 {\r
33 \r
34     using System;\r
35 \r
36     public struct SqlInt16 : INullable, IComparable\r
37     {\r
38 \r
39         private short _value;\r
40         private bool _isNull;\r
41 \r
42         public static readonly SqlInt16 Null = new SqlInt16(true);\r
43         public static readonly SqlInt16 MaxValue = new SqlInt16(short.MaxValue);\r
44         public static readonly SqlInt16 MinValue = new SqlInt16(short.MinValue);\r
45         public static readonly SqlInt16 Zero = new SqlInt16(0);\r
46 \r
47         \r
48         private SqlInt16(bool isNull)\r
49         {\r
50             _value = 0;\r
51             _isNull = isNull;\r
52         }\r
53         /**\r
54          * Constructor\r
55          * @param value A short whose value will be used for the new SqlInt16.\r
56          */\r
57         public SqlInt16(short value) \r
58         {\r
59             _value = value;\r
60             _isNull = false;\r
61         }\r
62 \r
63         /**\r
64          * Constructor\r
65          * @param value A int whose value will be used for the new SqlInt16.\r
66          */\r
67         public SqlInt16(int value) \r
68         {\r
69             if (value > short.MaxValue || value < short.MinValue)\r
70                 throw new OverflowException("the value is not legal - overflowing : " + value);\r
71 \r
72             _value = (short)value;\r
73             _isNull = false;\r
74         }\r
75 \r
76         \r
77         /**\r
78          * Indicates whether or not Value is null.\r
79          * @return true if Value is null, otherwise false.\r
80          */\r
81         public bool IsNull\r
82         {\r
83             get\r
84             {\r
85                 return _isNull;\r
86             }\r
87         }\r
88 \r
89 \r
90 \r
91         /**\r
92          * Gets the value of the SqlInt16 instance.\r
93          * @return the value of this instance\r
94          */\r
95         public short Value\r
96         {\r
97             get\r
98             {\r
99                 if(IsNull)\r
100                     throw new SqlNullValueException();\r
101                 return _value;\r
102             }\r
103         }\r
104 \r
105         /**\r
106          * Compares this instance to the supplied object and returns an indication of their relative values.\r
107          * @param obj The object to compare.\r
108          * @return A signed number indicating the relative values of the instance and the object.\r
109          * Less than zero This instance is less than object.\r
110          * Zero This instance is the same as object.\r
111          * Greater than zero This instance is greater than object -or-\r
112          * object is a null reference.\r
113          */\r
114         public int CompareTo(Object obj)\r
115         {\r
116             if (obj == null)\r
117                 return 1;\r
118 \r
119             if (obj is SqlInt16)\r
120             {\r
121                 SqlInt16 i = (SqlInt16)obj;\r
122 \r
123                 if (i.IsNull)\r
124                     return 1;\r
125                 if (this.IsNull)\r
126                     return -1;\r
127 \r
128                 return this._value.CompareTo(i._value);\r
129             }\r
130 \r
131             throw new ArgumentException("parameter obj is not SqlInt16 : " + obj.GetType().Name);\r
132 \r
133         }\r
134 \r
135         /**\r
136          * The addition operator computes the sum of the two SqlInt16 operands.\r
137          * @param x A SqlInt16 structure.\r
138          * @param y A SqlInt16 structure.\r
139          * @return The sum of the two SqlInt16 operands.\r
140          * If one of the parameters is null or null value - return SqlInt16.Null.\r
141          */\r
142         public static SqlInt16 Add(SqlInt16 x, SqlInt16 y)\r
143         {\r
144             if (x.IsNull || y.IsNull)\r
145                 return SqlInt16.Null;\r
146 \r
147             int sum  = checked(x._value + y._value);\r
148 \r
149             return new SqlInt16(sum);\r
150         }\r
151 \r
152         /**\r
153          * Computes the bitwise AND of its SqlInt16 operands.\r
154          * @param x A SqlInt16 instance.\r
155          * @param y A SqlInt16 instance.\r
156          * @return The results of the bitwise AND operation.\r
157          */\r
158         public static SqlInt16 BitwiseAnd(SqlInt16 x, SqlInt16 y)\r
159         {\r
160             if (x.IsNull || y.IsNull)\r
161                 return SqlInt16.Null;\r
162 \r
163             int res  = x._value & y._value;\r
164 \r
165             return new SqlInt16(res);\r
166         }\r
167 \r
168         /**\r
169          * Computes the bitwise OR of its SqlInt16 operands.\r
170          * @param x A SqlInt16 instance.\r
171          * @param y A SqlInt16 instance.\r
172          * @return The results of the bitwise OR operation.\r
173          */\r
174         public static SqlInt16 BitwiseOr(SqlInt16 x, SqlInt16 y)\r
175         {\r
176             if (x.IsNull || y.IsNull)\r
177                 return SqlInt16.Null;\r
178 \r
179             int res  = (ushort)x._value | (ushort)y._value;\r
180 \r
181             return new SqlInt16(res);\r
182         }\r
183 \r
184         /**\r
185          * The division operator divides the first SqlInt16 operand by the second.\r
186          * @param x A SqlInt16 instance.\r
187          * @param y A SqlInt16 instance.\r
188          * @return A SqlInt16 instance containing the results of the division operation.\r
189          * If one of the parameters is null or null value - return SqlInt16.Null.\r
190          */\r
191         public static SqlInt16 Divide(SqlInt16 x, SqlInt16 y)\r
192         {\r
193             int val = x._value / y._value;\r
194             return new SqlInt16(val);\r
195         }\r
196 \r
197         public override bool Equals(Object obj)\r
198         {\r
199             \r
200             if (obj == null)\r
201                 return false;\r
202 \r
203             if (obj is SqlInt16)\r
204             {\r
205                 SqlInt16 i = (SqlInt16)obj;\r
206 \r
207                 if (IsNull && i.IsNull)\r
208                     return true;\r
209 \r
210                 if (IsNull || i.IsNull)\r
211                     return false;\r
212 \r
213                 return _value == i._value;\r
214             }\r
215 \r
216             return false;\r
217         }\r
218 \r
219         \r
220 \r
221         /**\r
222          * Performs a logical comparison on two instances of SqlInt16 to determine if they are equal.\r
223          * @param x A SqlInt16 instance.\r
224          * @param y A SqlInt16 instance.\r
225          * @return true if the two values are equal, otherwise false.\r
226          * If one of the parameters is null or null value return SqlBoolean.Null.\r
227          */\r
228         public static SqlBoolean Equals(SqlInt16 x, SqlInt16 y)\r
229         {\r
230             if (x.IsNull || y.IsNull)\r
231                 return SqlBoolean.Null;\r
232 \r
233             if (x._value == y._value)\r
234                 return SqlBoolean.True;\r
235 \r
236             return SqlBoolean.False;\r
237         }\r
238 \r
239 \r
240         /**\r
241          * Compares two instances of SqlByte to determine if the first is greater than the second.\r
242          * @param x A SqlByte instance\r
243          * @param y A SqlByte instance\r
244          * @return A SqlBoolean that is True if the first instance is greater than the second instance, otherwise False.\r
245          * If either instance of SqlInt16 is null, the Value of the SqlBoolean will be Null.\r
246          */\r
247         public static SqlBoolean GreaterThan(SqlInt16 x, SqlInt16 y)\r
248         {\r
249             if (x.IsNull || y.IsNull)\r
250                 return SqlBoolean.Null;\r
251 \r
252             if (x._value > y._value)\r
253                 return SqlBoolean.True;\r
254 \r
255             return SqlBoolean.False;\r
256         }\r
257 \r
258         /**\r
259          * Compares two instances of SqlInt16 to determine if the first is greater than or equal to the second.\r
260          * @param x A SqlInt16 instance\r
261          * @param y A SqlInt16 instance\r
262          * @return A SqlBoolean that is True if the first instance is greaater than or equal to the second instance, otherwise False.\r
263          * If either instance of SqlInt16 is null, the Value of the SqlBoolean will be Null.\r
264          */\r
265         public static SqlBoolean GreaterThanOrEqual(SqlInt16 x, SqlInt16 y)\r
266         {\r
267             if (x.IsNull || y.IsNull)\r
268                 return SqlBoolean.Null;\r
269 \r
270             if (x._value >= y._value)\r
271                 return SqlBoolean.True;\r
272 \r
273             return SqlBoolean.False;\r
274         }\r
275 \r
276         /**\r
277          * Compares two instances of SqlInt16 to determine if the first is less than the second.\r
278          * @param x A SqlInt16 instance\r
279          * @param y A SqlInt16 instance\r
280          * @return A SqlBoolean that is True if the first instance is less than the second instance, otherwise False.\r
281          * If either instance of SqlInt16 is null, the Value of the SqlBoolean will be Null.\r
282          */\r
283         public static SqlBoolean LessThan(SqlInt16 x, SqlInt16 y)\r
284         {\r
285             if (x.IsNull || y.IsNull)\r
286                 return SqlBoolean.Null;\r
287 \r
288             if (x._value < y._value)\r
289                 return SqlBoolean.True;\r
290 \r
291             return SqlBoolean.False;\r
292         }\r
293 \r
294         /**\r
295          * Compares two instances of SqlInt16 to determine if the first is less than or equal to the second.\r
296          * @param x A SqlInt16 instance\r
297          * @param y A SqlInt16 instance\r
298          * @return A SqlBoolean that is True if the first instance is less than or equal to the second instance, otherwise False.\r
299          * If either instance of SqlInt16 is null, the Value of the SqlBoolean will be Null.\r
300          */\r
301         public static SqlBoolean LessThanOrEqual(SqlInt16 x, SqlInt16 y)\r
302         {\r
303             if (x.IsNull || y.IsNull)\r
304                 return SqlBoolean.Null;\r
305 \r
306             if (x._value <= y._value)\r
307                 return SqlBoolean.True;\r
308 \r
309             return SqlBoolean.False;\r
310         }\r
311 \r
312         /**\r
313          * Computes the remainder after dividing its first SqlInt16 operand by its second.\r
314          * @param x A SqlInt16 instance\r
315          * @param y A SqlInt16 instance\r
316          * @return A SqlInt16 instance whose Value contains the remainder.\r
317          */\r
318         public static SqlInt16 Mod(SqlInt16 x, SqlInt16 y)\r
319         {\r
320             if (x.IsNull || y.IsNull)\r
321                 return SqlInt16.Null;\r
322 \r
323             int mod = x._value % y._value;\r
324 \r
325             return new SqlInt16(mod);\r
326         }\r
327 \r
328         /**\r
329          * The multiplication operator computes the product of the two SqlInt16 operands.\r
330          * @param x A SqlInt16 instance\r
331          * @param y A SqlInt16 instance\r
332          * @return The product of the two SqlInt16 operands.\r
333          */\r
334         public static SqlInt16 Multiply(SqlInt16 x, SqlInt16 y)\r
335         {\r
336             if (x.IsNull || y.IsNull)\r
337                 return SqlInt16.Null;\r
338 \r
339             int res = checked(x._value * y._value);\r
340 \r
341             return new SqlInt16(res);\r
342         }\r
343 \r
344         /**\r
345          * Compares two instances of SqlInt16 to determine if they are equal.\r
346          * @param x A SqlInt16 instance\r
347          * @param y A SqlInt16 instance\r
348          * @return A SqlBoolean that is True if the two instances are not equal or False if the two instances are equal.\r
349          * If either instance of SqlInt16 is null, the Value of the SqlBoolean will be Null.\r
350          */\r
351         public static SqlBoolean NotEquals(SqlInt16 x, SqlInt16 y)\r
352         {\r
353             if (x.IsNull || y.IsNull)\r
354                 return SqlBoolean.Null;\r
355 \r
356             if (x._value != y._value)\r
357                 return SqlBoolean.True;\r
358 \r
359             return SqlBoolean.False;\r
360         }\r
361 \r
362         /**\r
363          * The ones complement operator performs a bitwise one's complement operation on its SqlInt16 operand.\r
364          * @param x A SqlInt16 instance\r
365          * @return A SqlInt16 instance whose Value property contains the ones complement of the SqlInt16 parameter.\r
366          */\r
367         public static SqlInt16 OnesComplement(SqlInt16 x)\r
368         {\r
369             int res  = x._value ^ 0xFFFF;\r
370 \r
371             return new SqlInt16(res);\r
372         }\r
373 \r
374         /**\r
375          * Converts the String representation of a number to its byte equivalent.\r
376          * @param s The String to be parsed.\r
377          * @return A SqlInt16 containing the value represented by the String.\r
378          */\r
379         public static SqlInt16 Parse(String s)\r
380         {\r
381             int res = short.Parse(s);\r
382             return new SqlInt16(res);\r
383         }\r
384 \r
385         /**\r
386          * The subtraction operator the second SqlInt16 operand from the first.\r
387          * @param x A SqlInt16 instance\r
388          * @param y A SqlInt16 instance\r
389          * @return The results of the subtraction operation.\r
390          */\r
391         public static SqlInt16 Subtract(SqlInt16 x, SqlInt16 y)\r
392         {\r
393             int res = x._value - y._value;\r
394 \r
395             return new SqlInt16(res);\r
396         }\r
397 \r
398         /**\r
399          * Performs a bitwise exclusive-OR operation on the supplied parameters.\r
400          * @param x A SqlInt16 instance\r
401          * @param y A SqlInt16 instance\r
402          * @return The results of the XOR operation.\r
403          */\r
404         public static SqlInt16 Xor(SqlInt16 x, SqlInt16 y)\r
405         {\r
406             int res  = x._value ^ y._value;\r
407 \r
408             return new SqlInt16(res);\r
409         }\r
410 \r
411         /**\r
412          * Converts this SqlInt16 structure to SqlBoolean.\r
413          * @return A SqlBoolean structure whose Value will be True if the SqlInt16 structure's Value is non-zero, False if the SqlInt16 is zero\r
414          * and Null if the SqlInt16 structure is Null.\r
415          */\r
416         public SqlBoolean ToSqlBoolean()\r
417         {\r
418             if (IsNull)\r
419                 return SqlBoolean.Null;\r
420 \r
421             if (_value == 0)\r
422                 return new SqlBoolean(0);\r
423 \r
424             return new SqlBoolean(1);\r
425         }\r
426 \r
427         /**\r
428          * Converts this SqlInt16 structure to SqlByte.\r
429          * @return A SqlByte structure whose Value equals the Value of this SqlInt16 structure.\r
430          */\r
431         public SqlByte ToSqlByte()\r
432         {\r
433             if (IsNull)\r
434                 return SqlByte.Null;\r
435 \r
436             int val = _value;\r
437 \r
438             if (val < 0 || val > 255)\r
439                 throw new OverflowException("Can not conver this instance to SqlByte - overflowing : " + val);\r
440 \r
441             return new SqlByte((byte)val);\r
442         }\r
443 \r
444         /**\r
445          * Converts this SqlInt16 structure to SqlDecimal.\r
446          * @return A SqlDecimal structure whose Value equals the Value of this SqlInt16 structure.\r
447          */\r
448         public SqlDecimal ToSqlDecimal()\r
449         {\r
450             if (IsNull)\r
451                 return SqlDecimal.Null;\r
452 \r
453             return new SqlDecimal(_value);\r
454         }\r
455 \r
456         /**\r
457          * Converts this SqlInt16 structure to SqlDecimal.\r
458          * @return A SqlDouble structure whose Value equals the Value of this SqlInt16 structure.\r
459          */\r
460         public SqlDouble ToSqlDouble()\r
461         {\r
462             if (IsNull)\r
463                 return SqlDouble.Null;\r
464 \r
465             return new SqlDouble(_value);\r
466         }\r
467 \r
468         /**\r
469          * Converts this SqlInt16 structure to SqlInt32.\r
470          * @return A SqlInt32 structure whose Value equals the Value of this SqlDouble structure.\r
471          */\r
472         public SqlInt32 ToSqlInt32()\r
473         {\r
474             if (IsNull)\r
475                 return SqlInt32.Null;\r
476 \r
477             return new SqlInt32(_value);\r
478         }\r
479 \r
480 \r
481         /**\r
482          * Converts this SqlInt16 structure to SqlInt64.\r
483          * @return A SqlInt64 structure whose Value equals the Value of this SqlInt16 structure.\r
484          */\r
485         public SqlInt64 ToSqlInt64()\r
486         {\r
487             if (IsNull)\r
488                 return SqlInt64.Null;\r
489 \r
490             return new SqlInt64(_value);\r
491         }\r
492 \r
493         /**\r
494          * Converts this SqlInt16 instance to SqlDouble.\r
495          * @return A SqlMoney instance whose Value equals the Value of this SqlInt16 instance.\r
496          */\r
497         public SqlMoney ToSqlMoney()\r
498         {\r
499             if (IsNull)\r
500                 return SqlMoney.Null;\r
501 \r
502             return new SqlMoney(_value);\r
503         }\r
504 \r
505         /**\r
506          * Converts this SqlInt16 instance to SqlSingle.\r
507          * @return A SqlSingle instance whose Value equals the Value of this SqlInt16 instance.\r
508          */\r
509         public SqlSingle ToSqlSingle()\r
510         {\r
511             if (IsNull)\r
512                 return SqlSingle.Null;\r
513 \r
514             return new SqlSingle(_value);\r
515         }\r
516 \r
517         /**\r
518          * Converts this SqlInt16 structure to SqlString.\r
519          * @return A SqlString structure whose value is a string representing the date and time contained in this SqlInt16 structure.\r
520          */\r
521         public SqlString ToSqlString()\r
522         {\r
523             return new SqlString(ToString());\r
524         }\r
525 \r
526 \r
527 \r
528         public override String ToString()\r
529         {\r
530             if (IsNull)\r
531                 return "null";\r
532             return _value.ToString();\r
533         }\r
534 \r
535         public static void main(String[] args)\r
536         {\r
537             SqlInt16 i1 = new SqlInt16(-2);\r
538             SqlInt16 i2 = new SqlInt16(-2);\r
539 \r
540             Console.WriteLine(BitwiseAnd(i1, i2));\r
541 \r
542         }\r
543     \r
544         public override int GetHashCode()\r
545         {\r
546             return _value;\r
547         }\r
548 \r
549         public static SqlInt16 operator + (SqlInt16 x, SqlInt16 y)\r
550         {\r
551             checked \r
552             {\r
553                 return new SqlInt16 ((short) (x.Value + y.Value));\r
554             }\r
555         }\r
556 \r
557         public static SqlInt16 operator & (SqlInt16 x, SqlInt16 y)\r
558         {\r
559             return new SqlInt16 ((short) (x.Value & y.Value));\r
560         }\r
561 \r
562         public static SqlInt16 operator | (SqlInt16 x, SqlInt16 y)\r
563         {\r
564             return new SqlInt16 ((short) ( x.Value | y.Value));\r
565         }\r
566 \r
567         public static SqlInt16 operator / (SqlInt16 x, SqlInt16 y)\r
568         {\r
569             checked \r
570             {\r
571                 return new SqlInt16 ((short) (x.Value / y.Value));\r
572             }\r
573         }\r
574 \r
575         public static SqlBoolean operator == (SqlInt16 x, SqlInt16 y)\r
576         {\r
577             if (x.IsNull || y.IsNull) \r
578                 return SqlBoolean.Null;\r
579             else\r
580                 return new SqlBoolean (x.Value == y.Value);\r
581         }\r
582 \r
583         public static SqlInt16 operator ^ (SqlInt16 x, SqlInt16 y)\r
584         {\r
585             return new SqlInt16 ((short) (x.Value ^ y.Value));\r
586         }\r
587 \r
588         public static SqlBoolean operator > (SqlInt16 x, SqlInt16 y)\r
589         {\r
590             if (x.IsNull || y.IsNull) \r
591                 return SqlBoolean.Null;\r
592             else\r
593                 return new SqlBoolean (x.Value > y.Value);\r
594         }\r
595 \r
596         public static SqlBoolean operator >= (SqlInt16 x, SqlInt16 y)\r
597         {\r
598             if (x.IsNull || y.IsNull) \r
599                 return SqlBoolean.Null;\r
600             else\r
601                 return new SqlBoolean (x.Value >= y.Value);\r
602         }\r
603 \r
604         public static SqlBoolean operator != (SqlInt16 x, SqlInt16 y)\r
605         {\r
606             if (x.IsNull || y.IsNull) \r
607                 return SqlBoolean.Null;\r
608             else \r
609                 return new SqlBoolean (!(x.Value == y.Value));\r
610         }\r
611 \r
612         public static SqlBoolean operator < (SqlInt16 x, SqlInt16 y)\r
613         {\r
614             if (x.IsNull || y.IsNull) \r
615                 return SqlBoolean.Null;\r
616             else\r
617                 return new SqlBoolean (x.Value < y.Value);\r
618         }\r
619 \r
620         public static SqlBoolean operator <= (SqlInt16 x, SqlInt16 y)\r
621         {\r
622             if (x.IsNull || y.IsNull) \r
623                 return SqlBoolean.Null;\r
624             else\r
625                 return new SqlBoolean (x.Value <= y.Value);\r
626         }\r
627 \r
628         public static SqlInt16 operator % (SqlInt16 x, SqlInt16 y)\r
629         {\r
630             return new SqlInt16 ((short) (x.Value % y.Value));\r
631         }\r
632 \r
633         public static SqlInt16 operator * (SqlInt16 x, SqlInt16 y)\r
634         {\r
635             checked \r
636             {\r
637                 return new SqlInt16 ((short) (x.Value * y.Value));\r
638             }\r
639         }\r
640 \r
641         public static SqlInt16 operator ~ (SqlInt16 x)\r
642         {\r
643             if (x.IsNull)\r
644                 return Null;\r
645                         \r
646             return new SqlInt16 ((short) (~x.Value));\r
647         }\r
648 \r
649         public static SqlInt16 operator - (SqlInt16 x, SqlInt16 y)\r
650         {\r
651             checked \r
652             {\r
653                 return new SqlInt16 ((short) (x.Value - y.Value));\r
654             }\r
655         }\r
656 \r
657         public static SqlInt16 operator - (SqlInt16 n)\r
658         {\r
659             checked \r
660             {\r
661                 return new SqlInt16 ((short) (-n.Value));\r
662             }\r
663         }\r
664 \r
665         public static explicit operator SqlInt16 (SqlBoolean x)\r
666         {\r
667             if (x.IsNull)\r
668                 return Null;\r
669             else\r
670                 return new SqlInt16 ((short)x.ByteValue);\r
671         }\r
672 \r
673         public static explicit operator SqlInt16 (SqlDecimal x)\r
674         {               \r
675             checked \r
676             {\r
677                 if (x.IsNull)\r
678                     return Null;\r
679                 else \r
680                     return new SqlInt16 ((short)x.Value);\r
681             }\r
682         }\r
683 \r
684         public static explicit operator SqlInt16 (SqlDouble x)\r
685         {\r
686             if (x.IsNull)\r
687                 return Null;\r
688             else \r
689                 return new SqlInt16 (checked ((short)x.Value));\r
690         }\r
691 \r
692         public static explicit operator short (SqlInt16 x)\r
693         {\r
694             return x.Value; \r
695         }\r
696 \r
697         public static explicit operator SqlInt16 (SqlInt32 x)\r
698         {\r
699             checked \r
700             {\r
701                 if (x.IsNull)\r
702                     return Null;\r
703                 else \r
704                     return new SqlInt16 ((short)x.Value);\r
705             }\r
706         }\r
707 \r
708         public static explicit operator SqlInt16 (SqlInt64 x)\r
709         {\r
710             if (x.IsNull)\r
711                 return Null;\r
712             else \r
713             {\r
714                 checked \r
715                 {\r
716                     return new SqlInt16 ((short)x.Value);\r
717                 }\r
718             }\r
719         }\r
720 \r
721         public static explicit operator SqlInt16 (SqlMoney x)\r
722         {\r
723             checked \r
724             {\r
725                 if (x.IsNull)\r
726                     return Null;\r
727                 else \r
728                     return new SqlInt16 ((short)x.Value);\r
729             }                   \r
730         }\r
731 \r
732 \r
733         public static explicit operator SqlInt16 (SqlSingle x)\r
734         {\r
735             if (x.IsNull)\r
736                 return Null;\r
737             else \r
738             {\r
739                 checked \r
740                 {\r
741                     return new SqlInt16 ((short)x.Value);\r
742                 }\r
743             }\r
744         }\r
745 \r
746         public static explicit operator SqlInt16 (SqlString x)\r
747         {       \r
748             if (x.IsNull)\r
749                 return Null;\r
750 \r
751             return SqlInt16.Parse (x.Value);\r
752         }\r
753 \r
754         public static implicit operator SqlInt16 (short x)\r
755         {\r
756             return new SqlInt16 (x);\r
757         }\r
758 \r
759         public static implicit operator SqlInt16 (SqlByte x)\r
760         {\r
761             return new SqlInt16 ((short)x.Value);\r
762         }\r
763 \r
764 \r
765     }}