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