2002-02-19 Duncan Mak <duncan@ximian.com>
authorDuncan Mak <duncan@mono-cvs.ximian.com>
Tue, 19 Feb 2002 12:28:23 +0000 (12:28 -0000)
committerDuncan Mak <duncan@mono-cvs.ximian.com>
Tue, 19 Feb 2002 12:28:23 +0000 (12:28 -0000)
    * Convert.cs: Finished up the missing methods in Convert.
    Added a new private method ConvertFromBase.

svn path=/trunk/mcs/; revision=2509

mcs/class/corlib/System.Runtime.Serialization/SerializationInfoEnumerator.cs
mcs/class/corlib/System/ChangeLog
mcs/class/corlib/System/Convert.cs

index 5e323a05fe88446fc51d335b6a07e234203ce8b4..a4d50af1d707f85ce92d93b5a9270cbd7801b871 100644 (file)
@@ -25,12 +25,12 @@ namespace System.Runtime.Serialization
                // Properties
                public SerializationEntry Current
                {
-                    get { return (SerializationEntry) ide.Value; }
+                       get { return (SerializationEntry) ide.Value; }
                }
 
                object IEnumerator.Current
                {                       
-                    get { return ide.Value; }
+                       get { return ide.Value; }
                }
 
                public string Name
@@ -58,6 +58,5 @@ namespace System.Runtime.Serialization
                {
                        ide.Reset ();
                }
-       }
-       
+       }       
 }
index 3e83b7fccc90193508ddd595c1dca5be441f60c9..3e3d02bd54c29dfd0a4d6ee6071dd2e549864db6 100644 (file)
@@ -1,3 +1,8 @@
+2002-02-19  Duncan Mak  <duncan@ximian.com>
+
+       * Convert.cs: Finished up the missing methods in Convert. Added a
+       new private method ConvertFromBase.
+
 2002-02-19  Dietmar Maurer  <dietmar@ximian.com>
 
        * String.cs: impl. IConvertible interface
index a1fc5667bac3f301cb2b72607938f228cfc34400..45c7e9d722bc4e2e10e7509ac0090ee4b602070a 100644 (file)
@@ -3,6 +3,7 @@
 //\r
 // Author:\r
 //   Derek Holden (dholden@draper.com)\r
+//   Duncan Mak (duncan@ximian.com)\r
 //\r
 // (C) Ximian, Inc.  http://www.ximian.com\r
 //\r
@@ -843,13 +844,13 @@ namespace System {
                        return Int16.Parse (value, provider);\r
                }\r
 \r
-               [MonoTODO]\r
+               \r
                public static short ToInt16 (string value, int fromBase)\r
                {\r
                        if (NotValidBase (fromBase))\r
                                throw new ArgumentException ("fromBase is not valid.");\r
                        \r
-                       return 0;\r
+                       return (short) ConvertFromBase (value, fromBase);\r
                }\r
 \r
                [CLSCompliant (false)]\r
@@ -979,13 +980,13 @@ namespace System {
                        return Int32.Parse (value, provider);\r
                }\r
 \r
-               [MonoTODO]\r
+               \r
                public static int ToInt32 (string value, int fromBase)\r
                {\r
                        if (NotValidBase (fromBase))\r
                                throw new ArgumentException ("fromBase is not valid.");\r
                        \r
-                       return 0;\r
+                       return ConvertFromBase (value, fromBase);\r
                }\r
                \r
                [CLSCompliant (false)]\r
@@ -1108,13 +1109,12 @@ namespace System {
                        return Int64.Parse (value, provider);\r
                }\r
 \r
-               [MonoTODO]\r
                public static long ToInt64 (string value, int fromBase)\r
                {\r
                        if (NotValidBase (fromBase))\r
                                throw new ArgumentException ("fromBase is not valid.");\r
                        \r
-                       return 0;\r
+                       return (long) ConvertFromBase (value, fromBase);\r
                }\r
 \r
                [CLSCompliant (false)]\r
@@ -1264,13 +1264,13 @@ namespace System {
                        return SByte.Parse (value, provider);\r
                }\r
 \r
-               [MonoTODO] [CLSCompliant (false)]\r
+               [CLSCompliant (false)]\r
                public static sbyte ToSByte (string value, int fromBase)\r
                {\r
                        if (NotValidBase (fromBase))\r
                                throw new ArgumentException ("fromBase is not valid.");\r
                        \r
-                       return 0;\r
+                       return (sbyte) ConvertFromBase (value, fromBase);\r
                }\r
                \r
                [CLSCompliant (false)]\r
@@ -1676,13 +1676,13 @@ namespace System {
                        return UInt16.Parse (value, provider);\r
                }\r
 \r
-               [MonoTODO] [CLSCompliant (false)]\r
+               [CLSCompliant (false)]\r
                public static ushort ToUInt16 (string value, int fromBase) \r
                {\r
                        if (NotValidBase (fromBase))\r
                                throw new ArgumentException ("fromBase is not valid.");\r
                        \r
-                       return 0;\r
+                       return (ushort) ConvertFromBase (value, fromBase);\r
                } \r
 \r
                [CLSCompliant (false)]\r
@@ -1980,13 +1980,13 @@ namespace System {
                        return UInt64.Parse (value, provider);\r
                }\r
 \r
-               [MonoTODO] [CLSCompliant (false)]\r
-               public static ulong TOUint64 (string value, int fromBase)\r
+               [CLSCompliant (false)]\r
+               public static ulong ToUint64 (string value, int fromBase)\r
                {\r
                        if (NotValidBase (fromBase))\r
                                throw new ArgumentException ("fromBase is not valid.");\r
 \r
-                       return 0;\r
+                       return (ulong) ConvertFromBase (value, fromBase);\r
                }                                             \r
 \r
                [CLSCompliant (false)]\r
@@ -2057,6 +2057,19 @@ namespace System {
                        return true;\r
                }\r
 \r
+               private static int ConvertFromBase (string value, int fromBase)\r
+               {\r
+                       int result = 0;\r
+\r
+                       foreach (char c in value) {\r
+                               if (Char.IsLetter (c))\r
+                                       result = (fromBase) * result + c - 'a' + 10;\r
+                               else\r
+                                       result = (fromBase) * result + c - '0';\r
+                       }\r
+                       return result;\r
+               }\r
+\r
                 // Lookup table for the conversion ToType method. Order\r
                // is important! Used by ToType for comparing the target\r
                // type, and uses hardcoded array indexes.\r