//\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
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
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
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
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
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
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
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