2002-06-27 Martin Baulig <martin@gnome.org>
[mono.git] / mcs / class / corlib / System / Char.cs
index 344e05a277e114c98d135b05f8fc9f75b3bda475..58e5dc33ab6b007959447b33e2e86857f7ff2914 100644 (file)
@@ -19,7 +19,8 @@ using System.Runtime.CompilerServices;
 
 namespace System {
        
-       public struct Char : IComparable { //, IFormattable, IConvertible {
+       [Serializable]
+       public struct Char : IComparable, IConvertible { //, IFormattable {
                public const char MaxValue = (char) 0xffff;
                public const char MinValue = (char) 0;
                
@@ -82,7 +83,8 @@ namespace System {
                                throw new ArgumentNullException (Locale.GetText ("str is a null reference"));
                        
                        if (index < 0 || index >= str.Length)
-                               throw new ArgumentOutOfRangeException (Locale.GetText ("The value of index is less than zero, or greater than or equal to the length of str"));
+                               throw new ArgumentOutOfRangeException (Locale.GetText ("The value of index is less "+
+                                                         "than zero, or greater than or equal to the length of str"));
                        
                        return GetUnicodeCategory (str[index]);
                }
@@ -112,7 +114,7 @@ namespace System {
                        
                        if (index < 0 || index >= str.Length)
                                throw new ArgumentOutOfRangeException (Locale.GetText (
-                                       "The value of index is less than zero, or greater than or equal to the length of str"));
+                                "The value of index is less than zero, or greater than or equal to the length of str"));
                        
                        return IsDigit (str[index]);
                }
@@ -127,7 +129,7 @@ namespace System {
                        
                        if (index < 0 || index >= str.Length)
                                throw new ArgumentOutOfRangeException (Locale.GetText (
-                                       "The value of index is less than zero, or greater than or equal to the length of str"));
+                                "The value of index is less than zero, or greater than or equal to the length of str"));
                        
                        return IsLetter (str[index]);
                }
@@ -147,11 +149,11 @@ namespace System {
                        
                        if (index < 0 || index >= str.Length)
                                throw new ArgumentOutOfRangeException (Locale.GetText (
-                                       "The value of index is less than zero, or greater than or equal to the length of str"));
+                                "The value of index is less than zero, or greater than or equal to the length of str"));
                        
                        return IsLetterOrDigit (str[index]);
                }
-               
+
                [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)]
                public static extern bool IsLower (char c);
                
@@ -162,7 +164,7 @@ namespace System {
                        
                        if (index < 0 || index >= str.Length)
                                throw new ArgumentOutOfRangeException (Locale.GetText (
-                                       "The value of index is less than zero, or greater than or equal to the length of str"));
+                                "The value of index is less than zero, or greater than or equal to the length of str"));
                        
                        return IsLower (str[index]);
                }
@@ -177,7 +179,7 @@ namespace System {
                        
                        if (index < 0 || index >= str.Length)
                                throw new ArgumentOutOfRangeException (Locale.GetText (
-                                       "The value of index is less than zero, or greater than or equal to the length of str"));
+                               "The value of index is less than zero, or greater than or equal to the length of str"));
                        
                        return IsNumber (str[index]);
                }
@@ -192,7 +194,7 @@ namespace System {
                        
                        if (index < 0 || index >= str.Length)
                                throw new ArgumentOutOfRangeException (Locale.GetText (
-                                       "The value of index is less than zero, or greater than or equal to the length of str"));
+                                "The value of index is less than zero, or greater than or equal to the length of str"));
                        
                        return IsPunctuation (str[index]);
                }
@@ -207,7 +209,7 @@ namespace System {
                        
                        if (index < 0 || index >= str.Length)
                                throw new ArgumentOutOfRangeException (Locale.GetText (
-                                       "The value of index is less than zero, or greater than or equal to the length of str"));
+                                "The value of index is less than zero, or greater than or equal to the length of str"));
                        
                        return IsSeparator (str[index]);
                }
@@ -222,7 +224,7 @@ namespace System {
                        
                        if (index < 0 || index >= str.Length)
                                throw new ArgumentOutOfRangeException (Locale.GetText (
-                                       "The value of index is less than zero, or greater than or equal to the length of str"));
+                                "The value of index is less than zero, or greater than or equal to the length of str"));
                        
                        return IsSurrogate (str[index]);
                }
@@ -252,7 +254,7 @@ namespace System {
                        
                        if (index < 0 || index >= str.Length)
                                throw new ArgumentOutOfRangeException (Locale.GetText (
-                                       "The value of index is less than zero, or greater than or equal to the length of str"));
+                                "The value of index is less than zero, or greater than or equal to the length of str"));
                        
                        return IsUpper (str[index]);
                }
@@ -277,13 +279,9 @@ namespace System {
                        if (str == null)
                                throw new ArgumentNullException (Locale.GetText ("str is a null reference"));
 
-                       int len = str.Length;
-                       if (len != 1){
-                               if (len < 1)
-                                       throw new ArgumentNullException ();
-                               else
-                                       throw new FormatException ();
-                       }
+                       if (str.Length != 1)
+                               throw new FormatException ("string contains more than one character.");
+                       
                        return str [0];
                }
 
@@ -312,5 +310,90 @@ namespace System {
                {
                        return TypeCode.Char;
                }         
+
+               object IConvertible.ToType (Type conversionType, IFormatProvider provider)
+               {
+                       return System.Convert.ToType(value, conversionType, provider);
+               }
+               
+               bool IConvertible.ToBoolean (IFormatProvider provider)
+               {
+                       throw new InvalidCastException();
+               }
+               
+               byte IConvertible.ToByte (IFormatProvider provider)
+               {
+                       return System.Convert.ToByte(value);
+               }
+               
+               char IConvertible.ToChar (IFormatProvider provider)
+               {
+                       return value;
+               }
+               
+               [CLSCompliant(false)]
+               DateTime IConvertible.ToDateTime (IFormatProvider provider)
+               {
+                       throw new InvalidCastException();
+               }
+               
+               decimal IConvertible.ToDecimal (IFormatProvider provider)
+               {
+                       throw new InvalidCastException();
+               }
+               
+               double IConvertible.ToDouble (IFormatProvider provider)
+               {
+                       throw new InvalidCastException();
+               }
+               
+               short IConvertible.ToInt16 (IFormatProvider provider)
+               {
+                       return System.Convert.ToInt16(value);
+               }
+               
+               int IConvertible.ToInt32 (IFormatProvider provider)
+               {
+                       return System.Convert.ToInt32(value);
+               }
+               
+               long IConvertible.ToInt64 (IFormatProvider provider)
+               {
+                       return System.Convert.ToInt64(value);
+               }
+               
+               [CLSCompliant(false)] 
+               sbyte IConvertible.ToSByte (IFormatProvider provider)
+               {
+                       return System.Convert.ToSByte(value);
+               }
+               
+               float IConvertible.ToSingle (IFormatProvider provider)
+               {
+                       throw new InvalidCastException();
+               }
+               
+               string IConvertible.ToString (IFormatProvider provider)
+               {
+                       return ToString(provider);
+               }
+
+               [CLSCompliant(false)]
+               ushort IConvertible.ToUInt16 (IFormatProvider provider)
+               {
+                       return System.Convert.ToUInt16(value);
+               }
+               
+               [CLSCompliant(false)]
+               uint IConvertible.ToUInt32 (IFormatProvider provider)
+               {
+                       return System.Convert.ToUInt32(value);
+               }
+               
+               [CLSCompliant(false)]
+               ulong IConvertible.ToUInt64 (IFormatProvider provider)
+               {
+                       return System.Convert.ToUInt64(value);
+               }
        }
 }