Browse Source

2002-02-19 Duncan Mak <[email protected]>

	    * Convert.cs: Finished up the missing methods in Convert.
	    Added a new private method ConvertFromBase.

svn path=/trunk/mcs/; revision=2509
Duncan Mak 24 years ago
parent
commit
26d9468923

+ 3 - 4
mcs/class/corlib/System.Runtime.Serialization/SerializationInfoEnumerator.cs

@@ -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 ();
 		}
-	}
-	
+	}	
 }

+ 5 - 0
mcs/class/corlib/System/ChangeLog

@@ -1,3 +1,8 @@
+2002-02-19  Duncan Mak  <[email protected]>
+
+	* Convert.cs: Finished up the missing methods in Convert. Added a
+	new private method ConvertFromBase.
+
 2002-02-19  Dietmar Maurer  <[email protected]>
 
 	* String.cs: impl. IConvertible interface

+ 26 - 13
mcs/class/corlib/System/Convert.cs

@@ -3,6 +3,7 @@
 //
 // Author:
 //   Derek Holden ([email protected])
+//   Duncan Mak ([email protected])
 //
 // (C) Ximian, Inc.  http://www.ximian.com
 //
@@ -843,13 +844,13 @@ namespace System {
 			return Int16.Parse (value, provider);
 		}
 
-		[MonoTODO]
+		
 		public static short ToInt16 (string value, int fromBase)
 		{
 			if (NotValidBase (fromBase))
 				throw new ArgumentException ("fromBase is not valid.");
 			
-			return 0;
+			return (short) ConvertFromBase (value, fromBase);
 		}
 
 		[CLSCompliant (false)]
@@ -979,13 +980,13 @@ namespace System {
 			return Int32.Parse (value, provider);
 		}
 
-		[MonoTODO]
+		
 		public static int ToInt32 (string value, int fromBase)
 		{
 			if (NotValidBase (fromBase))
 				throw new ArgumentException ("fromBase is not valid.");
 			
-			return 0;
+			return ConvertFromBase (value, fromBase);
 		}
 		
 		[CLSCompliant (false)]
@@ -1108,13 +1109,12 @@ namespace System {
 			return Int64.Parse (value, provider);
 		}
 
-		[MonoTODO]
 		public static long ToInt64 (string value, int fromBase)
 		{
 			if (NotValidBase (fromBase))
 				throw new ArgumentException ("fromBase is not valid.");
 			
-			return 0;
+			return (long) ConvertFromBase (value, fromBase);
 		}
 
 		[CLSCompliant (false)]
@@ -1264,13 +1264,13 @@ namespace System {
 			return SByte.Parse (value, provider);
 		}
 
-		[MonoTODO] [CLSCompliant (false)]
+		[CLSCompliant (false)]
 		public static sbyte ToSByte (string value, int fromBase)
 		{
 			if (NotValidBase (fromBase))
 				throw new ArgumentException ("fromBase is not valid.");
 			
-			return 0;
+			return (sbyte) ConvertFromBase (value, fromBase);
 		}
 		
 		[CLSCompliant (false)]
@@ -1676,13 +1676,13 @@ namespace System {
 			return UInt16.Parse (value, provider);
 		}
 
-		[MonoTODO] [CLSCompliant (false)]
+		[CLSCompliant (false)]
 		public static ushort ToUInt16 (string value, int fromBase) 
 		{
 			if (NotValidBase (fromBase))
 				throw new ArgumentException ("fromBase is not valid.");
 			
-			return 0;
+			return (ushort) ConvertFromBase (value, fromBase);
 		} 
 
 		[CLSCompliant (false)]
@@ -1980,13 +1980,13 @@ namespace System {
 			return UInt64.Parse (value, provider);
 		}
 
-		[MonoTODO] [CLSCompliant (false)]
-		public static ulong TOUint64 (string value, int fromBase)
+		[CLSCompliant (false)]
+		public static ulong ToUint64 (string value, int fromBase)
 		{
 			if (NotValidBase (fromBase))
 				throw new ArgumentException ("fromBase is not valid.");
 
-			return 0;
+			return (ulong) ConvertFromBase (value, fromBase);
 		}					      
 
 		[CLSCompliant (false)]
@@ -2057,6 +2057,19 @@ namespace System {
 			return true;
 		}
 
+		private static int ConvertFromBase (string value, int fromBase)
+		{
+			int result = 0;
+
+			foreach (char c in value) {
+				if (Char.IsLetter (c))
+					result = (fromBase) * result + c - 'a' + 10;
+				else
+					result = (fromBase) * result + c - '0';
+			}
+			return result;
+		}
+
                 // Lookup table for the conversion ToType method. Order
 		// is important! Used by ToType for comparing the target
 		// type, and uses hardcoded array indexes.