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