Bug 15572. Lookup KnownTypeCollection element types in MSSimpleNamespace
[mono.git] / mcs / class / corlib / System / Int32.cs
1 //
2 // System.Int32.cs
3 //
4 // Authors:
5 //   Miguel de Icaza (miguel@ximian.com)
6 //   Marek Safar (marek.safar@gmail.com)
7 //
8 // (C) Ximian, Inc.  http://www.ximian.com
9 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
10 // Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com)
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31
32 using System.Globalization;
33 using System.Threading;
34
35 namespace System {
36         
37         [Serializable]
38         [System.Runtime.InteropServices.ComVisible (true)]
39         public struct Int32 : IFormattable, IConvertible, IComparable, IComparable<Int32>, IEquatable <Int32>
40         {
41
42                 public const int MaxValue = 0x7fffffff;
43                 public const int MinValue = -2147483648;
44                 
45                 // This field is looked up by name in the runtime
46                 internal int m_value;
47
48                 public int CompareTo (object value)
49                 {
50                         if (value == null)
51                                 return 1;
52                         
53                         if (!(value is System.Int32))
54                                 throw new ArgumentException (Locale.GetText ("Value is not a System.Int32"));
55
56                         int xv = (int) value;
57                         if (m_value == xv)
58                                 return 0;
59                         if (m_value > xv)
60                                 return 1;
61                         else
62                                 return -1;
63                 }
64
65                 public override bool Equals (object obj)
66                 {
67                         if (!(obj is System.Int32))
68                                 return false;
69
70                         return ((int) obj) == m_value;
71                 }
72
73                 public override int GetHashCode ()
74                 {
75                         return m_value;
76                 }
77
78                 public int CompareTo (int value)
79                 {
80                         if (m_value == value)
81                                 return 0;
82                         if (m_value > value)
83                                 return 1;
84                         else
85                                 return -1;
86                 }
87
88                 public bool Equals (int obj)
89                 {
90                         return obj == m_value;
91                 }
92
93                 internal static bool ProcessTrailingWhitespace (bool tryParse, string s, int position, ref Exception exc)
94                 {
95                         int len = s.Length;
96                         
97                         for (int i = position; i < len; i++){
98                                 char c = s [i];
99                                 
100                                 if (c != 0 && !Char.IsWhiteSpace (c)){
101                                         if (!tryParse)
102                                                 exc = GetFormatException ();
103                                         return false;
104                                 }
105                         }
106                         return true;
107                 }
108
109                 internal static bool Parse (string s, bool tryParse, out int result, out Exception exc)
110                 {
111                         int val = 0;
112                         int len;
113                         int i, sign = 1;
114                         bool digits_seen = false;
115
116                         result = 0;
117                         exc = null;
118                         NumberFormatInfo nfi = Thread.CurrentThread.CurrentCulture.NumberFormat;
119
120                         if (s == null) {
121                                 if (!tryParse)
122                                         exc = new ArgumentNullException ("s");
123                                 return false;
124                         }
125
126                         len = s.Length;
127
128                         char c;
129                         for (i = 0; i < len; i++){
130                                 c = s [i];
131                                 if (!Char.IsWhiteSpace (c))
132                                         break;
133                         }
134                         
135                         if (i == len) {
136                                 if (!tryParse)
137                                         exc = GetFormatException ();
138                                 return false;
139                         }
140
141                         var ps_length = nfi.PositiveSign.Length;
142                         var ns_length = nfi.NegativeSign.Length;
143                         if (len > ps_length && string.CompareOrdinalUnchecked (s, i, ns_length, nfi.PositiveSign, 0, ps_length) == 0)
144                                 i += ps_length;
145                         else if (len > ns_length && string.CompareOrdinalUnchecked (s, i, ns_length, nfi.NegativeSign, 0, ns_length) == 0) {
146                                 sign = -1;
147                                 i += ns_length;
148                         }
149                         
150                         for (; i < len; i++){
151                                 c = s [i];
152
153                                 if (c == '\0') {
154                                         i = len;
155                                         continue;
156                                 }
157                                 
158                                 if (c >= '0' && c <= '9'){
159                                         byte d = (byte) (c - '0');
160                                                 
161                                         if (val > (MaxValue/10))
162                                                 goto overflow;
163                                         
164                                         if (val == (MaxValue/10)){
165                                                 if ((d > (MaxValue % 10)) && (sign == 1 || (d > ((MaxValue % 10) + 1))))
166                                                         goto overflow;
167                                                 if (sign == -1)
168                                                         val = (val * sign * 10) - d;
169                                                 else
170                                                         val = (val * 10) + d;
171
172                                                 if (ProcessTrailingWhitespace (tryParse, s, i + 1, ref exc)){
173                                                         result = val;
174                                                         return true;
175                                                 }
176                                                 goto overflow;
177                                         } else 
178                                                 val = val * 10 + d;
179                                         
180                                         digits_seen = true;
181                                 } else if (!ProcessTrailingWhitespace (tryParse, s, i, ref exc))
182                                         return false;
183                         }
184                         if (!digits_seen) {
185                                 if (!tryParse)
186                                         exc = GetFormatException ();
187                                 return false;
188                         }
189
190                         if (sign == -1)
191                                 result = val * sign;
192                         else
193                                 result = val;
194
195                         return true;
196
197                 overflow:
198                         if (!tryParse)
199                                 exc = new OverflowException ("Value is too large");
200                         return false;
201                 }
202
203                 public static int Parse (string s, IFormatProvider provider)
204                 {
205                         return Parse (s, NumberStyles.Integer, provider);
206                 }
207
208                 public static int Parse (string s, NumberStyles style)
209                 {
210                         return Parse (s, style, null);
211                 }
212
213                 internal static bool CheckStyle (NumberStyles style, bool tryParse, ref Exception exc)
214                 {
215                         if ((style & NumberStyles.AllowHexSpecifier) != 0) {
216                                 NumberStyles ne = style ^ NumberStyles.AllowHexSpecifier;
217                                 if ((ne & NumberStyles.AllowLeadingWhite) != 0)
218                                         ne ^= NumberStyles.AllowLeadingWhite;
219                                 if ((ne & NumberStyles.AllowTrailingWhite) != 0)
220                                         ne ^= NumberStyles.AllowTrailingWhite;
221                                 if (ne != 0) {
222                                         if (!tryParse)
223                                                 exc = new ArgumentException (
224                                                         "With AllowHexSpecifier only " + 
225                                                         "AllowLeadingWhite and AllowTrailingWhite " + 
226                                                         "are permitted.");
227                                         return false;
228                                 }
229                         } else if ((uint) style > (uint) NumberStyles.Any){
230                                 if (!tryParse)
231                                         exc = new ArgumentException ("Not a valid number style");
232                                 return false;
233                         }
234
235                         return true;
236                 }
237                 
238                 internal static bool JumpOverWhite (ref int pos, string s, bool reportError, bool tryParse, ref Exception exc)
239                 {
240                         while (pos < s.Length && Char.IsWhiteSpace (s [pos]))
241                                 pos++;
242
243                         if (reportError && pos >= s.Length) {
244                                 if (!tryParse)
245                                         exc = GetFormatException ();
246                                 return false;
247                         }
248
249                         return true;
250                 }
251
252                 internal static void FindSign (ref int pos, string s, NumberFormatInfo nfi, 
253                                       ref bool foundSign, ref bool negative)
254                 {
255                         if ((pos + nfi.NegativeSign.Length) <= s.Length &&
256                                 s.IndexOfOrdinalUnchecked (nfi.NegativeSign, pos, nfi.NegativeSign.Length) == pos) {
257                                 negative = true;
258                                 foundSign = true;
259                                 pos += nfi.NegativeSign.Length;
260                         } else if ((pos + nfi.PositiveSign.Length) <= s.Length &&
261                                 s.IndexOfOrdinalUnchecked (nfi.PositiveSign, pos, nfi.PositiveSign.Length) == pos) {
262                                 negative = false;
263                                 pos += nfi.PositiveSign.Length;
264                                 foundSign = true;
265                         } 
266                 }
267
268                 internal static void FindCurrency (ref int pos,
269                                                  string s, 
270                                                  NumberFormatInfo nfi,
271                                                  ref bool foundCurrency)
272                 {
273                         if ((pos + nfi.CurrencySymbol.Length) <= s.Length &&
274                              s.Substring (pos, nfi.CurrencySymbol.Length) == nfi.CurrencySymbol) {
275                                 foundCurrency = true;
276                                 pos += nfi.CurrencySymbol.Length;
277                         } 
278                 }
279
280                 internal static bool FindExponent (ref int pos, string s, ref int exponent, bool tryParse, ref Exception exc)
281                 {
282                                 exponent = 0;
283
284                                 if (pos >= s.Length || (s [pos] != 'e' && s[pos] != 'E')) {
285                                         exc = null;
286                                         return false;
287                                 }
288
289                                 var i = pos + 1;
290                                 if (i == s.Length) {
291                                         exc = tryParse ? null : GetFormatException ();
292                                         return true;
293                                 }
294
295                                 // negative exponent not valid for Int32
296                                 if (s [i] == '-') {
297                                         exc = tryParse ? null : new OverflowException ("Value too large or too small.");
298                                         return true;
299                                 }
300
301                                 if (s [i] == '+' && ++i == s.Length) {
302                                         exc = tryParse ? null : GetFormatException ();
303                                         return true;
304                                 }
305
306                                 long exp = 0; // temp long value
307                                 for (; i < s.Length; i++) {
308                                         if (!Char.IsDigit (s [i]))  {
309                                                 exc = tryParse ? null : GetFormatException ();
310                                                 return true;
311                                         }
312
313                                         // Reduce the risk of throwing an overflow exc
314                                         exp = checked (exp * 10 - (int) (s [i] - '0'));
315                                         if (exp < Int32.MinValue || exp > Int32.MaxValue) {
316                                                 exc = tryParse ? null : new OverflowException ("Value too large or too small.");
317                                                 return true;
318                                         }
319                                 }
320
321                                 // exp value saved as negative
322                                 exp = -exp;
323
324                                 exc = null;
325                                 exponent = (int)exp;
326                                 pos = i;
327                                 return true;
328                 }
329
330                 internal static bool FindOther (ref int pos,
331                                               string s, 
332                                               string other)
333                 {
334                         if ((pos + other.Length) <= s.Length &&
335                              s.Substring (pos, other.Length) == other) {
336                                 pos += other.Length;
337                                 return true;
338                         } 
339
340                         return false;
341                 }
342
343                 internal static bool ValidDigit (char e, bool allowHex)
344                 {
345                         if (allowHex)
346                                 return Char.IsDigit (e) || (e >= 'A' && e <= 'F') || (e >= 'a' && e <= 'f');
347
348                         return Char.IsDigit (e);
349                 }
350                 
351                 internal static Exception GetFormatException ()
352                 {
353                         return new FormatException ("Input string was not in the correct format");
354                 }
355                 
356                 internal static bool Parse (string s, NumberStyles style, IFormatProvider fp, bool tryParse, out int result, out Exception exc)
357                 {
358                         result = 0;
359                         exc = null;
360
361                         if (s == null) {
362                                 if (!tryParse)
363                                         exc = new ArgumentNullException ("s");
364                                 return false;
365                         }
366
367                         if (s.Length == 0) {
368                                 if (!tryParse)
369                                         exc = GetFormatException ();
370                                 return false;
371                         }
372
373                         NumberFormatInfo nfi = null;
374                         if (fp != null) {
375                                 Type typeNFI = typeof (System.Globalization.NumberFormatInfo);
376                                 nfi = (NumberFormatInfo) fp.GetFormat (typeNFI);
377                         }
378                         if (nfi == null)
379                                 nfi = Thread.CurrentThread.CurrentCulture.NumberFormat;
380
381                         if (!CheckStyle (style, tryParse, ref exc))
382                                 return false;
383
384                         bool AllowCurrencySymbol = (style & NumberStyles.AllowCurrencySymbol) != 0;
385                         bool AllowHexSpecifier = (style & NumberStyles.AllowHexSpecifier) != 0;
386                         bool AllowThousands = (style & NumberStyles.AllowThousands) != 0;
387                         bool AllowDecimalPoint = (style & NumberStyles.AllowDecimalPoint) != 0;
388                         bool AllowParentheses = (style & NumberStyles.AllowParentheses) != 0;
389                         bool AllowTrailingSign = (style & NumberStyles.AllowTrailingSign) != 0;
390                         bool AllowLeadingSign = (style & NumberStyles.AllowLeadingSign) != 0;
391                         bool AllowTrailingWhite = (style & NumberStyles.AllowTrailingWhite) != 0;
392                         bool AllowLeadingWhite = (style & NumberStyles.AllowLeadingWhite) != 0;
393                         bool AllowExponent = (style & NumberStyles.AllowExponent) != 0;
394
395                         int pos = 0;
396
397                         if (AllowLeadingWhite && !JumpOverWhite (ref pos, s, true, tryParse, ref exc))
398                                 return false;
399
400                         bool foundOpenParentheses = false;
401                         bool negative = false;
402                         bool foundSign = false;
403                         bool foundCurrency = false;
404
405                         // Pre-number stuff
406                         if (AllowParentheses && s [pos] == '(') {
407                                 foundOpenParentheses = true;
408                                 foundSign = true;
409                                 negative = true; // MS always make the number negative when there parentheses
410                                                  // even when NumberFormatInfo.NumberNegativePattern != 0!!!
411                                 pos++;
412                                 if (AllowLeadingWhite && !JumpOverWhite (ref pos, s, true, tryParse, ref exc))
413                                         return false;
414
415                                 if (s.Substring (pos, nfi.NegativeSign.Length) == nfi.NegativeSign) {
416                                         if (!tryParse)
417                                                 exc = GetFormatException ();
418                                         return false;
419                                 }
420                                 
421                                 if (s.Substring (pos, nfi.PositiveSign.Length) == nfi.PositiveSign) {
422                                         if (!tryParse)
423                                                 exc = GetFormatException ();
424                                         return false;
425                                 }
426                         }
427
428                         if (AllowLeadingSign && !foundSign) {
429                                 // Sign + Currency
430                                 FindSign (ref pos, s, nfi, ref foundSign, ref negative);
431                                 if (foundSign) {
432                                         if (AllowLeadingWhite && !JumpOverWhite (ref pos, s, true, tryParse, ref exc))
433                                                 return false;
434                                         if (AllowCurrencySymbol) {
435                                                 FindCurrency (ref pos, s, nfi,
436                                                               ref foundCurrency);
437                                                 if (foundCurrency && AllowLeadingWhite &&
438                                                                 !JumpOverWhite (ref pos, s, true, tryParse, ref exc))
439                                                         return false;
440                                         }
441                                 }
442                         }
443                         
444                         if (AllowCurrencySymbol && !foundCurrency) {
445                                 // Currency + sign
446                                 FindCurrency (ref pos, s, nfi, ref foundCurrency);
447                                 if (foundCurrency) {
448                                         if (AllowLeadingWhite && !JumpOverWhite (ref pos, s, true, tryParse, ref exc))
449                                                 return false;
450                                         if (foundCurrency) {
451                                                 if (!foundSign && AllowLeadingSign) {
452                                                         FindSign (ref pos, s, nfi, ref foundSign,
453                                                                   ref negative);
454                                                         if (foundSign && AllowLeadingWhite &&
455                                                                         !JumpOverWhite (ref pos, s, true, tryParse, ref exc))
456                                                                 return false;
457                                                 }
458                                         }
459                                 }
460                         }
461
462                         int number = 0;
463                         int nDigits = 0;
464                         int decimalPointPos = -1;
465                         int digitValue;
466                         char hexDigit;
467                                 
468                         // Number stuff
469                         while (pos < s.Length) {
470
471                                 if (!ValidDigit (s [pos], AllowHexSpecifier)) {
472                                         if (AllowThousands &&
473                                             (FindOther (ref pos, s, nfi.NumberGroupSeparator)
474                                                 || FindOther (ref pos, s, nfi.CurrencyGroupSeparator)))
475                                             continue;
476
477                                         if (AllowDecimalPoint && decimalPointPos < 0 &&
478                                             (FindOther (ref pos, s, nfi.NumberDecimalSeparator)
479                                                 || FindOther (ref pos, s, nfi.CurrencyDecimalSeparator))) {
480                                                 decimalPointPos = nDigits;
481                                             continue;
482                                         }
483
484                                         break;
485                                 }
486
487                                 nDigits++;
488
489                                 if (AllowHexSpecifier) {
490                                         hexDigit = s [pos++];
491                                         if (Char.IsDigit (hexDigit))
492                                                 digitValue = (int) (hexDigit - '0');
493                                         else if (Char.IsLower (hexDigit))
494                                                 digitValue = (int) (hexDigit - 'a' + 10);
495                                         else
496                                                 digitValue = (int) (hexDigit - 'A' + 10);
497
498                                         uint unumber = (uint)number;
499                                         if (tryParse){
500                                                 if ((unumber & 0xf0000000) != 0)
501                                                         return false;
502                                                 
503                                                 number = (int) (unumber * 16u + (uint) digitValue);
504                                         } else {
505                                                 number = (int)checked (unumber * 16u + (uint)digitValue);
506                                         }
507
508                                         continue;
509                                 }
510
511                                 try {
512                                         // Calculations done as negative
513                                         // (abs (MinValue) > abs (MaxValue))
514                                         number = checked (number * 10 - (int) (s [pos++] - '0'));
515                                 } catch (OverflowException) {
516                                         if (!tryParse)
517                                                 exc = new OverflowException ("Value too large or too small.");
518                                         return false;
519                                 }
520                         }
521
522                         // Post number stuff
523                         if (nDigits == 0) {
524                                 if (!tryParse)
525                                         exc = GetFormatException ();
526                                 return false;
527                         }
528
529                         int exponent = 0;
530                         if (AllowExponent)
531                                 if (FindExponent (ref pos, s, ref exponent, tryParse, ref exc) && exc != null)
532                                         return false;
533
534                         if (AllowTrailingSign && !foundSign) {
535                                 // Sign + Currency
536                                 FindSign (ref pos, s, nfi, ref foundSign, ref negative);
537                                 if (foundSign && pos < s.Length) {
538                                         if (AllowTrailingWhite && !JumpOverWhite (ref pos, s, true, tryParse, ref exc))
539                                                 return false;
540                                 }
541                         }
542                         
543                         if (AllowCurrencySymbol && !foundCurrency) {
544                                 if (AllowTrailingWhite && pos < s.Length && !JumpOverWhite (ref pos, s, false, tryParse, ref exc))
545                                         return false;
546                                 
547                                 // Currency + sign
548                                 FindCurrency (ref pos, s, nfi, ref foundCurrency);
549                                 if (foundCurrency  && pos < s.Length) {
550                                         if (AllowTrailingWhite  && !JumpOverWhite (ref pos, s, true, tryParse, ref exc))
551                                                 return false;
552                                         if (!foundSign && AllowTrailingSign)
553                                                 FindSign (ref pos, s, nfi, ref foundSign,
554                                                           ref negative);
555                                 }
556                         }
557                         
558                         if (AllowTrailingWhite && pos < s.Length && !JumpOverWhite (ref pos, s, false, tryParse, ref exc))
559                                 return false;
560
561                         if (foundOpenParentheses) {
562                                 if (pos >= s.Length || s [pos++] != ')') {
563                                         if (!tryParse)
564                                                 exc = GetFormatException ();
565                                         return false;
566                                 }
567                                 if (AllowTrailingWhite && pos < s.Length && !JumpOverWhite (ref pos, s, false, tryParse, ref exc))
568                                         return false;
569                         }
570
571                         if (pos < s.Length && s [pos] != '\u0000') {
572                                 if (!tryParse)
573                                         exc = GetFormatException ();
574                                 return false;
575                         }
576                         
577                         if (!negative && !AllowHexSpecifier){
578                                 if (tryParse){
579                                         long lval = -((long)number);
580
581                                         if (lval < MinValue || lval > MaxValue)
582                                                 return false;
583                                         number = (int) lval;
584                                 } else
585                                         number = checked (-number);
586                         }
587
588                         if (decimalPointPos >= 0)
589                                 exponent = exponent - nDigits + decimalPointPos;
590                         
591                         if (exponent < 0) {
592                                 //
593                                 // Any non-zero values after decimal point are not allowed
594                                 //
595                                 int remainder;
596                                 number = Math.DivRem (number, (int) Math.Pow (10, -exponent), out remainder);
597                                 if (remainder != 0) {
598                                         if (!tryParse)
599                                                 exc = new OverflowException ("Value too large or too small.");
600                                         return false;
601                                 }
602                         } else if (exponent > 0) {
603                                 //
604                                 // result *= 10^exponent
605                                 //
606                                 // Reduce the risk of throwing an overflow exc
607                                 //
608                                 double res = checked (Math.Pow (10, exponent) * number);
609                                 if (res < MinValue || res > MaxValue) {
610                                         if (!tryParse)
611                                                 exc = new OverflowException ("Value too large or too small.");
612                                         return false;
613                                 }
614
615                                 number = (int)res;
616                         }
617                         
618                         result = number;
619                         return true;
620                 }
621
622                 public static int Parse (string s) 
623                 {
624                         Exception exc;
625                         int res;
626
627                         if (!Parse (s, false, out res, out exc))
628                                 throw exc;
629
630                         return res;
631                 }
632
633                 public static int Parse (string s, NumberStyles style, IFormatProvider provider) 
634                 {
635                         Exception exc;
636                         int res;
637
638                         if (!Parse (s, style, provider, false, out res, out exc))
639                                 throw exc;
640
641                         return res;
642                 }
643
644                 public static bool TryParse (string s, out int result) 
645                 {
646                         Exception exc;
647                         if (!Parse (s, true, out result, out exc)) {
648                                 result = 0;
649                                 return false;
650                         }
651
652                         return true;
653                 }
654
655                 public static bool TryParse (string s, NumberStyles style, IFormatProvider provider, out int result) 
656                 {
657                         Exception exc;
658                         if (!Parse (s, style, provider, true, out result, out exc)) {
659                                 result = 0;
660                                 return false;
661                         }
662
663                         return true;
664                 }
665
666                 public override string ToString ()
667                 {
668                         return NumberFormatter.NumberToString (m_value, null);
669                 }
670
671                 public string ToString (IFormatProvider provider)
672                 {
673                         return NumberFormatter.NumberToString (m_value, provider);
674                 }
675
676                 public string ToString (string format)
677                 {
678                         return ToString (format, null);
679                 }
680
681                 public string ToString (string format, IFormatProvider provider)
682                 {
683                         return NumberFormatter.NumberToString (format, m_value, provider);
684                 }
685
686                 // =========== IConvertible Methods =========== //
687
688                 public TypeCode GetTypeCode ()
689                 {
690                         return TypeCode.Int32;
691                 }
692
693                 bool IConvertible.ToBoolean (IFormatProvider provider)
694                 {
695                         return System.Convert.ToBoolean (m_value);
696                 }
697
698                 byte IConvertible.ToByte (IFormatProvider provider)
699                 {
700                         return System.Convert.ToByte (m_value);
701                 }
702
703                 char IConvertible.ToChar (IFormatProvider provider)
704                 {
705                         return System.Convert.ToChar (m_value);
706                 }
707
708                 DateTime IConvertible.ToDateTime (IFormatProvider provider)
709                 {
710                         return System.Convert.ToDateTime (m_value);
711                 }
712
713                 decimal IConvertible.ToDecimal (IFormatProvider provider)
714                 {
715                         return System.Convert.ToDecimal (m_value);
716                 }
717
718                 double IConvertible.ToDouble (IFormatProvider provider)
719                 {
720                         return System.Convert.ToDouble (m_value);
721                 }
722
723                 short IConvertible.ToInt16 (IFormatProvider provider)
724                 {
725                         return System.Convert.ToInt16 (m_value);
726                 }
727
728                 int IConvertible.ToInt32 (IFormatProvider provider)
729                 {
730                         return m_value;
731                 }
732
733                 long IConvertible.ToInt64 (IFormatProvider provider)
734                 {
735                         return System.Convert.ToInt64 (m_value);
736                 }
737
738                 sbyte IConvertible.ToSByte (IFormatProvider provider)
739                 {
740                         return System.Convert.ToSByte (m_value);
741                 }
742
743                 float IConvertible.ToSingle (IFormatProvider provider)
744                 {
745                         return System.Convert.ToSingle (m_value);
746                 }
747
748                 object IConvertible.ToType (Type targetType, IFormatProvider provider)
749                 {
750                         if (targetType == null)
751                                 throw new ArgumentNullException ("targetType");
752                         return System.Convert.ToType (m_value, targetType, provider, false);
753                 }
754
755                 ushort IConvertible.ToUInt16 (IFormatProvider provider)
756                 {
757                         return System.Convert.ToUInt16 (m_value);
758                 }
759
760                 uint IConvertible.ToUInt32 (IFormatProvider provider)
761                 {
762                         return System.Convert.ToUInt32 (m_value);
763                 }
764
765                 ulong IConvertible.ToUInt64 (IFormatProvider provider)
766                 {
767                         return System.Convert.ToUInt64 (m_value);
768                 }
769         }
770 }