* Convert.cs: Finished up the missing methods in Convert.
Added a new private method ConvertFromBase.
svn path=/trunk/mcs/; revision=2509
// Properties
public SerializationEntry Current
{
// Properties
public SerializationEntry Current
{
- get { return (SerializationEntry) ide.Value; }
+ get { return (SerializationEntry) ide.Value; }
}
object IEnumerator.Current
{
}
object IEnumerator.Current
{
- get { return ide.Value; }
+ get { return ide.Value; }
+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
2002-02-19 Dietmar Maurer <dietmar@ximian.com>
* String.cs: impl. IConvertible interface
//\r
// Author:\r
// Derek Holden (dholden@draper.com)\r
//\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
//\r
// (C) Ximian, Inc. http://www.ximian.com\r
//\r
return Int16.Parse (value, provider);\r
}\r
\r
return Int16.Parse (value, provider);\r
}\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
public static short ToInt16 (string value, int fromBase)\r
{\r
if (NotValidBase (fromBase))\r
throw new ArgumentException ("fromBase is not valid.");\r
\r
+ return (short) ConvertFromBase (value, fromBase);\r
}\r
\r
[CLSCompliant (false)]\r
}\r
\r
[CLSCompliant (false)]\r
return Int32.Parse (value, provider);\r
}\r
\r
return Int32.Parse (value, provider);\r
}\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
public static int ToInt32 (string value, int fromBase)\r
{\r
if (NotValidBase (fromBase))\r
throw new ArgumentException ("fromBase is not valid.");\r
\r
+ return ConvertFromBase (value, fromBase);\r
}\r
\r
[CLSCompliant (false)]\r
}\r
\r
[CLSCompliant (false)]\r
return Int64.Parse (value, provider);\r
}\r
\r
return Int64.Parse (value, provider);\r
}\r
\r
public static long ToInt64 (string value, int fromBase)\r
{\r
if (NotValidBase (fromBase))\r
throw new ArgumentException ("fromBase is not valid.");\r
\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 (long) ConvertFromBase (value, fromBase);\r
}\r
\r
[CLSCompliant (false)]\r
}\r
\r
[CLSCompliant (false)]\r
return SByte.Parse (value, provider);\r
}\r
\r
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
public static sbyte ToSByte (string value, int fromBase)\r
{\r
if (NotValidBase (fromBase))\r
throw new ArgumentException ("fromBase is not valid.");\r
\r
+ return (sbyte) ConvertFromBase (value, fromBase);\r
}\r
\r
[CLSCompliant (false)]\r
}\r
\r
[CLSCompliant (false)]\r
return UInt16.Parse (value, provider);\r
}\r
\r
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
public static ushort ToUInt16 (string value, int fromBase) \r
{\r
if (NotValidBase (fromBase))\r
throw new ArgumentException ("fromBase is not valid.");\r
\r
+ return (ushort) ConvertFromBase (value, fromBase);\r
} \r
\r
[CLSCompliant (false)]\r
} \r
\r
[CLSCompliant (false)]\r
return UInt64.Parse (value, provider);\r
}\r
\r
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
{\r
if (NotValidBase (fromBase))\r
throw new ArgumentException ("fromBase is not valid.");\r
\r
+ return (ulong) ConvertFromBase (value, fromBase);\r
} \r
\r
[CLSCompliant (false)]\r
} \r
\r
[CLSCompliant (false)]\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
// 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