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