fc5e0de8e412cb89e8a4dc94bc089a1a8a179cc7
[mono.git] / mcs / class / corlib / System / Char.cs
1 //
2 // System.Char.cs
3 //
4 // Authors:
5 //   Andreas Nahr (ClassDevelopment@A-SoftTech.com)
6 //   Miguel de Icaza (miguel@ximian.com)
7 //   Jackson Harper (jackson@ximian.com)
8 //
9 // (C) Ximian, Inc.  http://www.ximian.com
10 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.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 // Note about the ToString()'s. ECMA says there's only a ToString() method, 
33 // BUT it is just a wrapper for ToString(null). However there is no other ToString
34 // in the docs. Turning to the NET framework sdk reveals that there is a 
35 // ToString(formatprovider) method, as well as a 'static ToString (char c)' method, 
36 // which appears to just be a Convert.ToString(char c) type method. ECMA also
37 // doesn't list this class as implementing IFormattable.
38
39 using System.Globalization;
40 using System.Runtime.CompilerServices;
41 #if NET_2_0
42 using System.Runtime.InteropServices;
43 #endif
44
45 namespace System
46 {
47         [Serializable]
48 #if NET_2_0
49         [ComVisible (true)]
50         public struct Char : IComparable, IConvertible, IComparable <char>, IEquatable <char>
51 #else
52         public struct Char : IComparable, IConvertible
53 #endif
54         {
55                 public const char MaxValue = (char) 0xffff;
56                 public const char MinValue = (char) 0;
57
58                 internal char m_value;
59
60                 static Char ()
61                 {
62                         unsafe {
63                                 GetDataTablePointers (out category_data, out numeric_data, out numeric_data_values,
64                                         out to_lower_data_low, out to_lower_data_high, out to_upper_data_low, out to_upper_data_high);
65                         }
66                 }
67
68                 private readonly unsafe static byte *category_data;
69                 private readonly unsafe static byte *numeric_data;
70                 private readonly unsafe static double *numeric_data_values;
71                 private readonly unsafe static ushort *to_lower_data_low;
72                 private readonly unsafe static ushort *to_lower_data_high;
73                 private readonly unsafe static ushort *to_upper_data_low;
74                 private readonly unsafe static ushort *to_upper_data_high;
75
76                 [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)]
77                 private unsafe static extern void GetDataTablePointers (out byte *category_data,
78                                 out byte *numeric_data, out double *numeric_data_values,
79                                 out ushort *to_lower_data_low, out ushort *to_lower_data_high,
80                                 out ushort *to_upper_data_low, out ushort *to_upper_data_high);
81
82                 public int CompareTo (object v)
83                 {
84                         if (v == null)
85                                 return 1;
86                         
87                         if (!(v is System.Char))
88                                 throw new ArgumentException (Locale.GetText ("Value is not a System.Char"));
89
90                         char xv = (char) v;
91                         if (m_value == xv)
92                                 return 0;
93
94                         if (m_value > xv)
95                                 return 1;
96                         else
97                                 return -1;
98                 }
99
100                 public override bool Equals (object o)
101                 {
102                         if (!(o is Char))
103                                 return false;
104
105                         return ((char) o) == m_value;
106                 }
107
108 #if NET_2_0
109                 public int CompareTo (char value)
110                 {
111                         if (m_value == value)
112                                 return 0;
113
114                         if (m_value > value)
115                                 return 1;
116                         else
117                                 return -1;
118                 }
119
120                 public static string ConvertFromUtf32 (int utf32)
121                 {
122                         if (utf32 < 0 || utf32 > 0x10FFFF)
123                                 throw new ArgumentOutOfRangeException ("utf32", "The argument must be from 0 to 0x10FFFF.");
124                         if (0xD800 <= utf32 && utf32 <= 0xDFFF)
125                                 throw new ArgumentOutOfRangeException ("utf32", "The argument must not be in surrogate pair range.");
126                         if (utf32 < 0x10000)
127                                 return new string ((char) utf32, 1);
128                         utf32 -= 0x10000;
129                         return new string (
130                                 new char [] {(char) ((utf32 >> 10) + 0xD800),
131                                 (char) (utf32 % 0x0400 + 0xDC00)});
132                 }
133
134                 public static int ConvertToUtf32 (char highSurrogate, char lowSurrogate)
135                 {
136                         if (highSurrogate < 0xD800 || 0xDBFF < highSurrogate)
137                                 throw new ArgumentOutOfRangeException ("highSurrogate");
138                         if (lowSurrogate < 0xDC00 || 0xDFFF < lowSurrogate)
139                                 throw new ArgumentOutOfRangeException ("lowSurrogate");
140
141                         return 0x10000 + ((highSurrogate - 0xD800) << 10) + (lowSurrogate - 0xDC00);
142                 }
143
144                 public static int ConvertToUtf32 (string s, int index)
145                 {
146                         if (s == null)
147                                 throw new ArgumentNullException ("s");
148                         if (index < 0 || index >= s.Length)
149                                 throw new ArgumentOutOfRangeException ("index");
150                         if (!Char.IsSurrogate (s [index]))
151                                 return s [index];
152                         if (!Char.IsHighSurrogate (s [index])
153                             || index == s.Length - 1
154                             || !Char.IsLowSurrogate (s [index + 1]))
155                                 throw new ArgumentException (String.Format ("The string contains invalid surrogate pair character at {0}", index));
156                         return ConvertToUtf32 (s [index], s [index + 1]);
157                 }
158
159                 public bool Equals (char value)
160                 {
161                         return m_value == value;
162                 }
163
164                 public static bool IsSurrogatePair (char high, char low)
165                 {
166                         return '\uD800' <= high && high <= '\uDBFF'
167                                 && '\uDC00' <= low && low <= '\uDFFF';
168                 }
169
170                 public static bool IsSurrogatePair (string s, int index)
171                 {
172                         if (s == null)
173                                 throw new ArgumentNullException ("s");
174                         if (index < 0 || index >= s.Length)
175                                 throw new ArgumentOutOfRangeException ("index");
176                         return index + 1 < s.Length && IsSurrogatePair (s [index], s [index + 1]);
177                 }
178 #endif
179
180                 public override int GetHashCode ()
181                 {
182                         return m_value;
183                 }
184
185                 public static double GetNumericValue (char c)
186                 {
187                         if (c > (char)0x3289) {
188                                 if (c >= (char)0xFF10 && c <= (char)0xFF19)
189                                         return (c - 0xFF10); // Numbers 0-9
190
191                                 // Default not set data
192                                 return -1;
193                         }
194                         else {
195                                 unsafe {
196                                         return numeric_data_values [numeric_data [c]];
197                                 }
198                         }
199                         
200                 }
201
202                 public static double GetNumericValue (string str, int index)
203                 {
204                         if (str == null) 
205                                 throw new ArgumentNullException ("str");
206                         
207                         if (index < 0 || index >= str.Length)
208                                 throw new ArgumentOutOfRangeException (Locale.GetText (
209                                         "The value of index is less than zero, or greater than or equal to the length of str."));       
210                         
211                         return GetNumericValue (str[index]);
212                 }
213
214                 public static UnicodeCategory GetUnicodeCategory (char c)
215                 {
216                         unsafe {
217                                 return (UnicodeCategory)(category_data [c]);
218                         }
219                 }
220
221                 public static UnicodeCategory GetUnicodeCategory (string str, int index)
222                 {
223                         if (str == null) 
224                                 throw new ArgumentNullException ("str");
225                         
226                         if (index < 0 || index >= str.Length)
227                                 throw new ArgumentOutOfRangeException (Locale.GetText (
228                                         "The value of index is less than zero, or greater than or equal to the length of str."));
229                         
230                         return GetUnicodeCategory (str[index]);
231                 }
232
233                 public static bool IsControl (char c)
234                 {
235                         unsafe {
236                                 return (category_data [c] == (byte)UnicodeCategory.Control);
237                         }
238                 }
239
240                 public static bool IsControl (string str, int index)
241                 {
242                         if (str == null) 
243                                 throw new ArgumentNullException ("str");
244                         
245                         if (index < 0 || index >= str.Length)
246                                 throw new ArgumentOutOfRangeException (Locale.GetText (
247                                         "The value of index is less than zero, or greater than or equal to the length of str."));
248                         
249                         return IsControl (str[index]);
250                 }       
251
252                 public static bool IsDigit (char c)
253                 {
254                         unsafe {
255                                 return (category_data [c] == (byte)UnicodeCategory.DecimalDigitNumber);
256                         }
257                 }
258
259                 public static bool IsDigit (string str, int index)
260                 {
261                         if (str == null) 
262                                 throw new ArgumentNullException ("str");
263                         
264                         if (index < 0 || index >= str.Length)
265                                 throw new ArgumentOutOfRangeException (Locale.GetText (
266                                         "The value of index is less than zero, or greater than or equal to the length of str."));
267                         
268                         return IsDigit (str[index]);
269                 }
270
271 #if NET_2_0
272                 public static bool IsHighSurrogate (char c)
273                 {
274                         return c >= '\uD800' && c <= '\uDBFF';
275                 }
276
277                 public static bool IsHighSurrogate (string s, int index)
278                 {
279                         if (s == null) 
280                                 throw new ArgumentNullException ("s");
281                         
282                         if (index < 0 || index >= s.Length)
283                                 throw new ArgumentOutOfRangeException ("index");
284                         
285                         return IsHighSurrogate (s [index]);
286                 }
287 #endif
288
289                 public static bool IsLetter (char c)
290                 {
291                         unsafe {
292                                 UnicodeCategory Category = (UnicodeCategory)category_data [c];
293                                 switch (Category) {
294                                 case UnicodeCategory.UppercaseLetter:
295                                 case UnicodeCategory.LowercaseLetter:
296                                 case UnicodeCategory.TitlecaseLetter:
297                                 case UnicodeCategory.ModifierLetter:
298                                 case UnicodeCategory.OtherLetter:
299                                         return true;
300                                 default:
301                                         return false;
302                                 }
303                         }
304                 }
305
306                 public static bool IsLetter (string str, int index)
307                 {
308                         if (str == null) 
309                                 throw new ArgumentNullException ("str");
310                         
311                         if (index < 0 || index >= str.Length)
312                                 throw new ArgumentOutOfRangeException (Locale.GetText (
313                                         "The value of index is less than zero, or greater than or equal to the length of str."));
314                         
315                         return IsLetter (str[index]);
316                 }
317
318                 public static bool IsLetterOrDigit (char c)
319                 {
320                         unsafe {
321                                 UnicodeCategory Category = (UnicodeCategory)category_data [c];
322                                 switch (Category) {
323                                 case UnicodeCategory.DecimalDigitNumber:
324                                 case UnicodeCategory.UppercaseLetter:
325                                 case UnicodeCategory.LowercaseLetter:
326                                 case UnicodeCategory.TitlecaseLetter:
327                                 case UnicodeCategory.ModifierLetter:
328                                 case UnicodeCategory.OtherLetter:
329                                         return true;
330                                 default:
331                                         return false;
332                                 }
333                         }
334                 }
335
336                 public static bool IsLetterOrDigit (string str, int index)
337                 {
338                         if (str == null) 
339                                 throw new ArgumentNullException ("str");
340                         
341                         if (index < 0 || index >= str.Length)
342                                 throw new ArgumentOutOfRangeException (Locale.GetText (
343                                         "The value of index is less than zero, or greater than or equal to the length of str."));
344                         
345                         return IsLetterOrDigit (str[index]);
346                 }
347
348                 public static bool IsLower (char c)
349                 {
350                         unsafe {
351                                 return (category_data [c] == (byte)UnicodeCategory.LowercaseLetter);
352                         }
353                 }
354                 
355                 public static bool IsLower (string str, int index)
356                 {
357                         if (str == null) 
358                                 throw new ArgumentNullException ("str");
359                         
360                         if (index < 0 || index >= str.Length)
361                                 throw new ArgumentOutOfRangeException (Locale.GetText (
362                                         "The value of index is less than zero, or greater than or equal to the length of str."));
363                         
364                         return IsLower (str[index]);
365                 }
366
367 #if NET_2_0
368                 public static bool IsLowSurrogate (char c)
369                 {
370                         return c >= '\uDC00' && c <= '\uDFFF';
371                 }
372
373                 public static bool IsLowSurrogate (string s, int index)
374                 {
375                         if (s == null) 
376                                 throw new ArgumentNullException ("s");
377                         
378                         if (index < 0 || index >= s.Length)
379                                 throw new ArgumentOutOfRangeException ("index");
380                         
381                         return IsLowSurrogate (s [index]);
382                 }
383 #endif
384
385                 public static bool IsNumber (char c)
386                 {
387                         unsafe {
388                                 UnicodeCategory Category = (UnicodeCategory)category_data [c];
389                                 switch (Category) {
390                                 case UnicodeCategory.DecimalDigitNumber:
391                                 case UnicodeCategory.LetterNumber:
392                                 case UnicodeCategory.OtherNumber:
393                                         return true;
394                                 default:
395                                         return false;
396                                 }
397                         }
398                 }
399                 
400                 public static bool IsNumber (string str, int index)
401                 {
402                         if (str == null) 
403                                 throw new ArgumentNullException ("str");
404                         
405                         if (index < 0 || index >= str.Length)
406                                 throw new ArgumentOutOfRangeException (Locale.GetText (
407                                         "The value of index is less than zero, or greater than or equal to the length of str."));
408                         
409                         return IsNumber (str[index]);
410                 }
411
412                 public static bool IsPunctuation (char c)
413                 {
414                         unsafe {
415                                 UnicodeCategory Category = (UnicodeCategory)category_data [c];
416                                 switch (Category) {
417                                 case UnicodeCategory.ConnectorPunctuation:
418                                 case UnicodeCategory.DashPunctuation:
419                                 case UnicodeCategory.OpenPunctuation:
420                                 case UnicodeCategory.ClosePunctuation:
421                                 case UnicodeCategory.InitialQuotePunctuation:
422                                 case UnicodeCategory.FinalQuotePunctuation:
423                                 case UnicodeCategory.OtherPunctuation:
424                                         return true;
425                                 default:
426                                         return false;
427                                 }
428                         }
429                 }
430                 
431                 public static bool IsPunctuation (string str, int index)
432                 {
433                         if (str == null) 
434                                 throw new ArgumentNullException ("str");
435                         
436                         if (index < 0 || index >= str.Length)
437                                 throw new ArgumentOutOfRangeException (Locale.GetText (
438                                         "The value of index is less than zero, or greater than or equal to the length of str."));
439                         
440                         return IsPunctuation (str[index]);
441                 }
442
443                 public static bool IsSeparator (char c)
444                 {
445                         unsafe {
446                                 UnicodeCategory Category = (UnicodeCategory)category_data [c];
447                                 switch (Category) {
448                                 case UnicodeCategory.SpaceSeparator:
449                                 case UnicodeCategory.LineSeparator:
450                                 case UnicodeCategory.ParagraphSeparator:
451                                         return true;
452                                 default:
453                                         return false;
454                                 }
455                         }
456                 }
457                 
458                 public static bool IsSeparator (string str, int index)
459                 {
460                         if (str == null) 
461                                 throw new ArgumentNullException ("str");
462                         
463                         if (index < 0 || index >= str.Length)
464                                 throw new ArgumentOutOfRangeException (Locale.GetText (
465                                         "The value of index is less than zero, or greater than or equal to the length of str."));
466                         
467                         return IsSeparator (str[index]);
468                 }
469
470                 public static bool IsSurrogate (char c)
471                 {
472                         unsafe {
473                                 return (category_data [c] == (byte)UnicodeCategory.Surrogate);
474                         }
475                 }
476                 
477                 public static bool IsSurrogate (string str, int index)
478                 {
479                         if (str == null) 
480                                 throw new ArgumentNullException ("str");
481                         
482                         if (index < 0 || index >= str.Length)
483                                 throw new ArgumentOutOfRangeException (Locale.GetText (
484                                         "The value of index is less than zero, or greater than or equal to the length of str."));
485                         
486                         return IsSurrogate (str[index]);
487                 }
488
489                 public static bool IsSymbol (char c)
490                 {
491                         unsafe {
492                                 UnicodeCategory Category = (UnicodeCategory)category_data [c];
493                                 switch (Category) {
494                                 case UnicodeCategory.MathSymbol:
495                                 case UnicodeCategory.CurrencySymbol:
496                                 case UnicodeCategory.ModifierSymbol:
497                                 case UnicodeCategory.OtherSymbol:
498                                         return true;
499                                 default:
500                                         return false;
501                                 }
502                         }
503                 }
504                 
505                 public static bool IsSymbol (string str, int index)
506                 {
507                         if (str == null) 
508                                 throw new ArgumentNullException ("str");
509                         
510                         if (index < 0 || index >= str.Length)
511                                 throw new ArgumentOutOfRangeException (Locale.GetText (
512                                         "The value of index is less than zero, or greater than or equal to the length of str."));
513                         
514                         return IsSymbol (str[index]);
515                 }
516
517                 public static bool IsUpper (char c)
518                 {
519                         unsafe {
520                                 return (category_data [c] == (byte)UnicodeCategory.UppercaseLetter);
521                         }
522                 }
523                 
524                 public static bool IsUpper (string str, int index)
525                 {
526                         if (str == null) 
527                                 throw new ArgumentNullException ("str");
528                         
529                         if (index < 0 || index >= str.Length)
530                                 throw new ArgumentOutOfRangeException (Locale.GetText (
531                                         "The value of index is less than zero, or greater than or equal to the length of str."));
532                         
533                         return IsUpper (str[index]);
534                 }
535
536                 public static bool IsWhiteSpace (char c)
537                 {
538                         unsafe {
539                                 if (category_data [c] == (byte)UnicodeCategory.SpaceSeparator)
540                                         return true;
541                                 
542                                 switch (c) {
543                                 case (char)0x9:
544                                 case (char)0x0a:
545                                 case (char)0x0b:
546                                 case (char)0x0c:
547                                 case (char)0x0d:
548                                 case (char)0x85: // NEL 
549                                 case (char)0x2028: // Line Separator
550                                 case (char)0x2029: // Paragraph Separator
551 #if NET_2_0
552                                 case (char)0x205F: // Medium Mathematical Space
553 #endif
554                                         return true;
555                                 default:
556                                         return false;
557                                 }
558                         }
559                 }
560                 
561                 public static bool IsWhiteSpace (string str, int index)
562                 {
563                         if (str == null) 
564                                 throw new ArgumentNullException ("str");
565                         
566                         if (index < 0 || index >= str.Length)
567                                 throw new ArgumentOutOfRangeException (Locale.GetText (
568                                         "The value of index is less than zero, or greater than or equal to the length of str."));
569                         
570                         return IsWhiteSpace (str[index]);
571                 }
572
573 #if NET_2_0
574                 public static bool TryParse (string s, out char result)
575                 {
576                         if (s == null || s.Length != 1) {
577                                 result = (char) 0;
578                                 return false;
579                         }
580
581                         result = s [0];
582                         return true;
583                 }
584 #endif
585
586                 public static char Parse (string str)
587                 {
588                         if (str == null) 
589                                 throw new ArgumentNullException ("str");
590
591                         if (str.Length != 1)
592                                 throw new FormatException ("string contains more than one character.");
593                         
594                         return str [0];
595                 }
596
597                 public static char ToLower (char c)
598                 {
599                         return ToLower (c, CultureInfo.CurrentCulture);
600                 }
601
602 #if NET_2_0
603                 public static char ToLowerInvariant (char c)
604 #else
605                 internal static char ToLowerInvariant (char c)
606 #endif
607                 {
608                         unsafe {
609                                 if (c <= ((char)0x24cf))
610                                         return (char) to_lower_data_low [c];
611                                 if (c >= ((char)0xff21))
612                                         return (char) to_lower_data_high[c - 0xff21];
613                         }
614                         return c;
615                 }
616
617                 public static char ToLower (char c, CultureInfo culture)
618                 {
619                         if (culture == null)
620                                 throw new ArgumentNullException ("culture");
621                         if (culture.LCID == 0x007F) // Invariant
622                                 return ToLowerInvariant (c);
623
624                         return culture.TextInfo.ToLower (c);
625                 }
626
627                 public static char ToUpper (char c)
628                 {
629                         return ToUpper (c, CultureInfo.CurrentCulture);
630                 }
631
632 #if NET_2_0
633                 public static char ToUpperInvariant (char c)
634 #else
635                 internal static char ToUpperInvariant (char c)
636 #endif
637                 {
638                         unsafe {
639                                 if (c <= ((char)0x24e9))
640                                         return (char) to_upper_data_low [c];
641                                 if (c >= ((char)0xff21))
642                                         return (char) to_upper_data_high [c - 0xff21];
643                         }
644                         return c;
645                 }
646
647                 public static char ToUpper (char c, CultureInfo culture)
648                 {
649                         if (culture == null)
650                                 throw new ArgumentNullException ("culture");
651                         if (culture.LCID == 0x007F) // Invariant
652                                 return ToUpperInvariant (c);
653
654                         return culture.TextInfo.ToUpper (c);
655                 }
656                 
657                 public override string ToString ()
658                 {
659                         // LAMESPEC: ECMA draft lists this as returning ToString (null), 
660                         // However it doesn't list another ToString() method.
661                         return new String (m_value, 1);
662                 }
663
664                 public static string ToString(char c)
665                 {
666                         return new String (c, 1);
667                 }
668
669                 public string ToString (IFormatProvider fp)
670                 {
671                         // LAMESPEC: ECMA draft doesn't say Char implements IFormattable
672                         return new String (m_value, 1);
673                 }
674
675                 // =========== IConvertible Methods =========== //
676                 
677                 public TypeCode GetTypeCode ()
678                 {
679                         return TypeCode.Char;
680                 }         
681
682                 object IConvertible.ToType (Type conversionType, IFormatProvider provider)
683                 {
684                         return System.Convert.ToType(m_value, conversionType, provider);
685                 }
686                 
687                 bool IConvertible.ToBoolean (IFormatProvider provider)
688                 {
689                         throw new InvalidCastException();
690                 }
691                 
692                 byte IConvertible.ToByte (IFormatProvider provider)
693                 {
694                         return System.Convert.ToByte(m_value);
695                 }
696                 
697                 char IConvertible.ToChar (IFormatProvider provider)
698                 {
699                         return m_value;
700                 }
701                 
702                 DateTime IConvertible.ToDateTime (IFormatProvider provider)
703                 {
704                         throw new InvalidCastException();
705                 }
706                 
707                 decimal IConvertible.ToDecimal (IFormatProvider provider)
708                 {
709                         throw new InvalidCastException();
710                 }
711                 
712                 double IConvertible.ToDouble (IFormatProvider provider)
713                 {
714                         throw new InvalidCastException();
715                 }
716                 
717                 short IConvertible.ToInt16 (IFormatProvider provider)
718                 {
719                         return System.Convert.ToInt16(m_value);
720                 }
721                 
722                 int IConvertible.ToInt32 (IFormatProvider provider)
723                 {
724                         return System.Convert.ToInt32(m_value);
725                 }
726                 
727                 long IConvertible.ToInt64 (IFormatProvider provider)
728                 {
729                         return System.Convert.ToInt64(m_value);
730                 }
731                 
732                 sbyte IConvertible.ToSByte (IFormatProvider provider)
733                 {
734                         return System.Convert.ToSByte(m_value);
735                 }
736                 
737                 float IConvertible.ToSingle (IFormatProvider provider)
738                 {
739                         throw new InvalidCastException();
740                 }
741                 
742                 ushort IConvertible.ToUInt16 (IFormatProvider provider)
743                 {
744                         return System.Convert.ToUInt16(m_value);
745                 }
746                 
747                 uint IConvertible.ToUInt32 (IFormatProvider provider)
748                 {
749                         return System.Convert.ToUInt32(m_value);
750                 }
751                 
752                 ulong IConvertible.ToUInt64 (IFormatProvider provider)
753                 {
754                         return System.Convert.ToUInt64(m_value);
755                 }
756         }
757 }
758