//\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
// UI64 | X X X X X X X X X X X X X X\r
//\r
\r
-using System.Security.Cryptography;\r
using System.Globalization;\r
+using System.Security.Cryptography;\r
+using System.Text;\r
\r
namespace System {\r
\r
- [CLSCompliant(false)]\r
+// [CLSCompliant(false)]\r
public sealed class Convert {\r
+\r
+ // Fields\r
+ public static readonly object DBNull = System.DBNull.Value;\r
\r
+ private Convert () {}\r
+\r
// ========== BASE 64 Conversions ========== //\r
// the BASE64 convert methods are using the Base64 converting methods\r
// from System.Security.Cryptography.ToBase64Transform and\r
if (inArray == null)\r
throw new ArgumentNullException();\r
\r
- int len = inArray.Length;\r
- if (len < 4 || len % 4 != 0)\r
+ if ((offset < 0) || (length < 0) || (offset + length > inArray.Length))\r
+ throw new ArgumentOutOfRangeException();\r
+ \r
+ if (length < 4 || length % 4 != 0)\r
throw new FormatException();\r
\r
- byte[] inArr = new System.Text.UnicodeEncoding().GetBytes(inArray);\r
+ byte[] inArr = new System.Text.UTF8Encoding().GetBytes(inArray, offset, length);\r
FromBase64Transform t = new FromBase64Transform();\r
\r
return t.TransformFinalBlock(inArr, 0, inArr.Length);\r
\r
return FromBase64CharArray(inArr, 0, inArr.Length);\r
}\r
+\r
+ public static TypeCode GetTypeCode (object value)\r
+ {\r
+ if (value == null)\r
+ return TypeCode.Empty;\r
+ else \r
+ return Type.GetTypeCode (value.GetType ());\r
+ }\r
+\r
+ public static bool IsDBNull (object value)\r
+ {\r
+ if (value is DBNull)\r
+ return true;\r
+ else\r
+ return false;\r
+ }\r
\r
public static int ToBase64CharArray(byte[] inArray, int offsetIn, int length, \r
char[] outArray, int offsetOut)\r
return (value != 0); \r
}\r
\r
+ [CLSCompliant (false)]\r
public static bool ToBoolean (sbyte value) \r
{ \r
return (value != 0); \r
{\r
return Boolean.Parse (value);\r
}\r
- \r
+\r
+ public static bool ToBoolean (string value, IFormatProvider provider)\r
+ {\r
+ return Boolean.Parse (value); // provider is ignored.\r
+ }\r
+\r
+ [CLSCompliant (false)]\r
public static bool ToBoolean (uint value) \r
{ \r
return (value != 0);\r
}\r
\r
+ [CLSCompliant (false)]\r
public static bool ToBoolean (ulong value) \r
{ \r
return (value != 0); \r
}\r
\r
+ [CLSCompliant (false)]\r
public static bool ToBoolean (ushort value) \r
{ \r
return (value != 0); \r
}\r
\r
+ public static bool ToBoolean (object value)\r
+ {\r
+ return ToBoolean (value, null);\r
+ }\r
+\r
+ public static bool ToBoolean (object value, IFormatProvider provider)\r
+ {\r
+ if (value == null)\r
+ return false;\r
+ return ((IConvertible) value).ToBoolean (provider);\r
+ }\r
+\r
// ========== Byte Conversions ========== //\r
\r
public static byte ToByte (bool value) \r
\r
return (byte)value;\r
}\r
+\r
+ public static byte ToByte (DateTime value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
+ }\r
\r
- public static byte ToByte (decimal value) \r
+ public static byte ToByte (decimal value)\r
{ \r
if (value > Byte.MaxValue || value < Byte.MinValue)\r
throw new OverflowException (Locale.GetText (\r
return (byte)value;\r
}\r
\r
+ [CLSCompliant (false)]\r
public static byte ToByte (sbyte value) \r
{ \r
if (value < Byte.MinValue)\r
{\r
return Byte.Parse (value, provider);\r
}\r
- \r
+\r
+ public static byte ToByte (string value, int fromBase)\r
+ {\r
+\r
+ int retVal = ConvertFromBase (value, fromBase);\r
+\r
+ if (retVal < (int) Byte.MinValue || retVal > (int) Byte.MaxValue)\r
+ throw new OverflowException ();\r
+ else\r
+ return (byte) retVal;\r
+ }\r
+\r
+ [CLSCompliant (false)]\r
public static byte ToByte (uint value) \r
{ \r
if (value > Byte.MaxValue)\r
return (byte)value;\r
}\r
\r
+ [CLSCompliant (false)]\r
public static byte ToByte (ulong value) \r
{ \r
if (value > Byte.MaxValue)\r
return (byte)value;\r
}\r
\r
+ [CLSCompliant (false)]\r
public static byte ToByte (ushort value) \r
{ \r
if (value > Byte.MaxValue)\r
return (byte)value;\r
}\r
\r
+ public static byte ToByte (object value)\r
+ {\r
+ return ToByte (value, null);\r
+ }\r
+\r
+ public static byte ToByte (object value, IFormatProvider provider)\r
+ {\r
+ if (value == null)\r
+ return 0;\r
+ return ((IConvertible) value).ToByte (provider);\r
+ }\r
+\r
// ========== Char Conversions ========== //\r
- \r
+\r
+ public static char ToChar (bool value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
+ }\r
+ \r
public static char ToChar (byte value) \r
{ \r
return (char)value;\r
return value;\r
}\r
\r
+ public static char ToChar (DateTime value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
+ }\r
+\r
+ public static char ToChar (decimal value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
+ }\r
+\r
+ public static char ToChar (double value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
+ }\r
+ \r
public static char ToChar (int value) \r
{ \r
if (value > Char.MaxValue || value < Char.MinValue)\r
return (char)value; \r
}\r
\r
+ public static char ToChar (float value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
+ }\r
+\r
+ [CLSCompliant (false)]\r
public static char ToChar (sbyte value) \r
{ \r
if (value < Char.MinValue)\r
{\r
return Char.Parse (value);\r
}\r
- \r
+\r
+ public static char ToChar (string value, IFormatProvider provider)\r
+ {\r
+ return Char.Parse (value); // provider is ignored.\r
+ }\r
+\r
+ [CLSCompliant (false)]\r
public static char ToChar (uint value) \r
{ \r
if (value > Char.MaxValue)\r
return (char)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static char ToChar (ulong value) \r
{ \r
if (value > Char.MaxValue)\r
return (char)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static char ToChar (ushort value) \r
{ \r
if (value > Char.MaxValue)\r
return (char)value; \r
}\r
\r
+ public static char ToChar (object value)\r
+ {\r
+ return ToChar (value, null);\r
+ }\r
+\r
+ public static char ToChar (object value, IFormatProvider provider)\r
+ {\r
+ if (value == null)\r
+ return (char) 0;\r
+ return ((IConvertible) value).ToChar (provider);\r
+ }\r
+\r
// ========== DateTime Conversions ========== //\r
\r
public static DateTime ToDateTime (string value) \r
return DateTime.Parse (value, provider);\r
}\r
\r
+ public static DateTime ToDateTime (bool value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
+ }\r
+\r
+ public static DateTime ToDateTime (byte value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
+ }\r
+\r
+ public static DateTime ToDateTime (char value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
+ }\r
+\r
+ public static DateTime ToDateTime (DateTime value)\r
+ {\r
+ return value;\r
+ }\r
+\r
+ public static DateTime ToDateTime (decimal value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
+ }\r
+\r
+ public static DateTime ToDateTime (double value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
+ }\r
+\r
+ public static DateTime ToDateTime (short value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
+ }\r
+\r
+ public static DateTime ToDateTime (int value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
+ }\r
+\r
+ public static DateTime ToDateTime (long value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
+ }\r
+\r
+ public static DateTime ToDateTime (float value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
+ }\r
+\r
+ public static DateTime ToDateTime (object value)\r
+ {\r
+ return ToDateTime (value, null);\r
+ }\r
+\r
+ public static DateTime ToDateTime (object value, IFormatProvider provider)\r
+ {\r
+ if (value == null)\r
+ return DateTime.MinValue;\r
+ return ((IConvertible) value).ToDateTime (provider);\r
+ }\r
+\r
+ [CLSCompliant (false)]\r
+ public static DateTime ToDateTime (sbyte value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
+ }\r
+ [CLSCompliant (false)]\r
+ public static DateTime ToDateTime (ushort value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
+ }\r
+\r
+ [CLSCompliant (false)]\r
+ public static DateTime ToDateTime (uint value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
+ }\r
+\r
+ [CLSCompliant (false)]\r
+ public static DateTime ToDateTime (ulong value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
+ }\r
+\r
// ========== Decimal Conversions ========== //\r
\r
public static decimal ToDecimal (bool value) \r
{ \r
return (decimal)value; \r
}\r
- \r
+\r
+ public static decimal ToDecimal (char value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
+ }\r
+\r
+ public static decimal ToDecimal (DateTime value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
+ }\r
+ \r
public static decimal ToDecimal (decimal value) \r
{ \r
return value; \r
}\r
\r
public static decimal ToDecimal (float value) \r
- { \r
- if (value > (double)Decimal.MaxValue || value < (double)Decimal.MinValue) \r
- throw new OverflowException (Locale.GetText (\r
- "Value is greater than Decimal.MaxValue or less than Decimal.MinValue"));\r
-\r
- return (decimal)value; \r
+ {\r
+ return (decimal) value;\r
}\r
\r
public static decimal ToDecimal (int value) \r
return (decimal)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static decimal ToDecimal (sbyte value) \r
{ \r
return (decimal)value; \r
{\r
return Decimal.Parse (value, provider);\r
}\r
- \r
+\r
+ [CLSCompliant (false)]\r
public static decimal ToDecimal (uint value) \r
{ \r
return (decimal)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static decimal ToDecimal (ulong value) \r
{ \r
return (decimal)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static decimal ToDecimal (ushort value) \r
{ \r
return (decimal)value; \r
}\r
\r
+ public static decimal ToDecimal (object value)\r
+ {\r
+ return ToDecimal (value, null);\r
+ }\r
+\r
+ public static decimal ToDecimal (object value, IFormatProvider provider)\r
+ {\r
+ if (value == null)\r
+ return new Decimal (0);\r
+ return ((IConvertible) value).ToDecimal (provider);\r
+ }\r
+ \r
+\r
// ========== Double Conversions ========== //\r
\r
public static double ToDouble (bool value) \r
\r
public static double ToDouble (byte value) \r
{ \r
- return (double)value; \r
+ return (double) value;\r
+ }\r
+\r
+ public static double ToDouble (char value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
+ }\r
+\r
+ public static double ToDouble (DateTime value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
}\r
\r
public static double ToDouble (decimal value) \r
\r
public static double ToDouble (float value) \r
{ \r
- return (double)value; \r
+ return (double) value;\r
}\r
\r
public static double ToDouble (int value) \r
return (double)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static double ToDouble (sbyte value) \r
{ \r
return (double)value; \r
{\r
return Double.Parse (value, provider);\r
}\r
- \r
+\r
+ [CLSCompliant (false)]\r
public static double ToDouble (uint value) \r
{ \r
return (double)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static double ToDouble (ulong value) \r
{ \r
return (double)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static double ToDouble (ushort value) \r
{ \r
return (double)value; \r
}\r
\r
+ public static double ToDouble (object value)\r
+ {\r
+ return ToDouble (value, null);\r
+ }\r
+\r
+ public static double ToDouble (object value, IFormatProvider provider)\r
+ {\r
+ if (value == null)\r
+ return 0.0;\r
+ return ((IConvertible) value).ToDouble (provider);\r
+ }\r
+\r
// ========== Int16 Conversions ========== //\r
\r
public static short ToInt16 (bool value) \r
}\r
\r
public static short ToInt16 (char value) \r
- { \r
+ {\r
if (value > Int16.MaxValue) \r
throw new OverflowException (Locale.GetText (\r
"Value is greater than Int16.MaxValue"));\r
\r
- return (short)value; \r
+ return (short)value;\r
+ }\r
+\r
+ public static short ToInt16 (DateTime value) \r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
}\r
\r
public static short ToInt16 (decimal value) \r
return (short)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static short ToInt16 (sbyte value) \r
{ \r
return (short)value; \r
{\r
return Int16.Parse (value, provider);\r
}\r
- \r
+\r
+ \r
+ public static short ToInt16 (string value, int fromBase)\r
+ {\r
+ return Convert.ToInt16 (ConvertFromBase (value, fromBase));\r
+ }\r
+\r
+ [CLSCompliant (false)]\r
public static short ToInt16 (uint value) \r
{ \r
if (value > Int16.MaxValue) \r
return (short)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static short ToInt16 (ulong value) \r
{ \r
if (value > (ulong)Int16.MaxValue) \r
throw new OverflowException (Locale.GetText (\r
"Value is greater than Int16.MaxValue"));\r
-\r
return (short)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static short ToInt16 (ushort value) \r
{ \r
if (value > Int16.MaxValue) \r
return (short)value; \r
}\r
\r
+ public static short ToInt16 (object value)\r
+ {\r
+ return ToInt16 (value, null);\r
+ }\r
+\r
+ public static short ToInt16 (object value, IFormatProvider provider)\r
+ {\r
+ if (value == null)\r
+ return 0;\r
+ return ((IConvertible) value).ToInt16 (provider);\r
+ }\r
+ \r
// ========== Int32 Conversions ========== //\r
\r
public static int ToInt32 (bool value) \r
{ \r
return (int)value; \r
}\r
+\r
+ public static int ToInt32 (DateTime value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
+ }\r
\r
public static int ToInt32 (decimal value) \r
{ \r
return (int)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static int ToInt32 (sbyte value) \r
{ \r
return (int)value; \r
{\r
return Int32.Parse (value, provider);\r
}\r
- \r
+\r
+ \r
+ public static int ToInt32 (string value, int fromBase)\r
+ {\r
+ return ConvertFromBase (value, fromBase);\r
+ }\r
+ \r
+ [CLSCompliant (false)]\r
public static int ToInt32 (uint value) \r
{ \r
if (value > Int32.MaxValue) \r
return (int)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static int ToInt32 (ulong value) \r
{ \r
if (value > Int32.MaxValue) \r
return (int)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static int ToInt32 (ushort value) \r
{ \r
return (int)value; \r
}\r
\r
+ public static int ToInt32 (object value)\r
+ {\r
+ return ToInt32 (value, null);\r
+ }\r
+\r
+ public static int ToInt32 (object value, IFormatProvider provider)\r
+ {\r
+ if (value == null)\r
+ return 0;\r
+ return ((IConvertible) value).ToInt32 (provider);\r
+ }\r
+\r
// ========== Int64 Conversions ========== //\r
\r
public static long ToInt64 (bool value) \r
\r
public static long ToInt64 (byte value) \r
{ \r
- return (long)value; \r
+ return (long)(ulong)value; \r
}\r
\r
public static long ToInt64 (char value) \r
{ \r
return (long)value; \r
}\r
+\r
+ public static long ToInt64 (DateTime value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
+ }\r
\r
public static long ToInt64 (decimal value) \r
{ \r
"Value is greater than Int64.MaxValue or less than Int64.MinValue"));\r
\r
// Returned Even-Rounded\r
- return (long)(Math.Round (value)); \r
+ return (long)(Math.Round (value));\r
}\r
\r
public static long ToInt64 (float value) \r
return value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static long ToInt64 (sbyte value) \r
{ \r
return (long)value; \r
{\r
return Int64.Parse (value, provider);\r
}\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
+ return ConvertFromBase64 (value, fromBase);\r
+ }\r
+\r
+ [CLSCompliant (false)]\r
public static long ToInt64 (uint value) \r
{ \r
- return (long)value; \r
+ return (long)(ulong)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static long ToInt64 (ulong value) \r
{ \r
if (value > Int64.MaxValue) \r
return (long)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static long ToInt64 (ushort value) \r
{ \r
- return (long)value; \r
+ return (long)(ulong)value; \r
+ }\r
+\r
+ public static long ToInt64 (object value)\r
+ {\r
+ return ToInt64 (value, null);\r
}\r
\r
+ public static long ToInt64 (object value, IFormatProvider provider)\r
+ {\r
+ if (value == null)\r
+ return 0;\r
+ return ((IConvertible) value).ToInt64 (provider);\r
+ }\r
+ \r
// ========== SByte Conversions ========== //\r
- \r
+\r
+ [CLSCompliant (false)]\r
public static sbyte ToSByte (bool value) \r
{ \r
return (sbyte)(value ? 1 : 0); \r
}\r
- \r
+\r
+ [CLSCompliant (false)]\r
public static sbyte ToSByte (byte value) \r
{ \r
if (value > SByte.MaxValue)\r
return (sbyte)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static sbyte ToSByte (char value) \r
{ \r
if (value > SByte.MaxValue)\r
\r
return (sbyte)value;\r
}\r
- \r
+\r
+ [CLSCompliant (false)]\r
+ public static sbyte ToSByte (DateTime value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
+ }\r
+ \r
+ [CLSCompliant (false)] \r
public static sbyte ToSByte (decimal value) \r
{ \r
if (value > SByte.MaxValue || value < SByte.MinValue)\r
// Returned Even-Rounded\r
return (sbyte)(Math.Round (value));\r
}\r
- \r
+\r
+ [CLSCompliant (false)]\r
public static sbyte ToSByte (double value) \r
{ \r
if (value > SByte.MaxValue || value < SByte.MinValue)\r
return (sbyte)(Math.Round (value));\r
}\r
\r
+ [CLSCompliant (false)]\r
public static sbyte ToSByte (float value) \r
{ \r
if (value > SByte.MaxValue || value < SByte.MinValue)\r
return (sbyte)(Math.Round ( (double)value));\r
}\r
\r
+ [CLSCompliant (false)]\r
public static sbyte ToSByte (int value) \r
{ \r
if (value > SByte.MaxValue || value < SByte.MinValue)\r
return (sbyte)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static sbyte ToSByte (long value) \r
{ \r
if (value > SByte.MaxValue || value < SByte.MinValue)\r
return (sbyte)value;\r
}\r
\r
+ [CLSCompliant (false)]\r
public static sbyte ToSByte (sbyte value) \r
{ \r
return value;\r
}\r
- \r
+\r
+ [CLSCompliant (false)]\r
public static sbyte ToSByte (short value) \r
{ \r
if (value > SByte.MaxValue || value < SByte.MinValue)\r
return (sbyte)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static sbyte ToSByte (string value) \r
{\r
return SByte.Parse (value);\r
}\r
-\r
+ \r
+ [CLSCompliant (false)]\r
public static sbyte ToSByte (string value, IFormatProvider provider) \r
{\r
return SByte.Parse (value, provider);\r
}\r
- \r
+\r
+ [CLSCompliant (false)]\r
+ public static sbyte ToSByte (string value, int fromBase)\r
+ {\r
+ int retVal = ConvertFromBase (value, fromBase);\r
+\r
+ if (retVal == 255)\r
+ return (sbyte)-1;\r
+\r
+ if (retVal < (int) SByte.MinValue || retVal > (int) SByte.MaxValue)\r
+ throw new OverflowException ();\r
+ else\r
+ return (sbyte) retVal;\r
+ }\r
+ \r
+ [CLSCompliant (false)]\r
public static sbyte ToSByte (uint value) \r
{ \r
if (value > SByte.MaxValue)\r
return (sbyte)value;\r
}\r
\r
+ [CLSCompliant (false)]\r
public static sbyte ToSByte (ulong value) \r
{ \r
if (value > (ulong)SByte.MaxValue)\r
return (sbyte)value;\r
}\r
\r
+ [CLSCompliant (false)]\r
public static sbyte ToSByte (ushort value) \r
{ \r
if (value > SByte.MaxValue)\r
return (sbyte)value;\r
}\r
\r
+ [CLSCompliant (false)]\r
+ public static sbyte ToSByte (object value)\r
+ {\r
+ return ToSByte (value, null);\r
+ }\r
+\r
+ [CLSCompliant (false)]\r
+ public static sbyte ToSByte (object value, IFormatProvider provider)\r
+ {\r
+ if (value == null)\r
+ return 0;\r
+ return ((IConvertible) value).ToSByte (provider);\r
+ }\r
+\r
// ========== Single Conversions ========== //\r
\r
public static float ToSingle (bool value) \r
{ \r
return (float)value; \r
}\r
+\r
+ public static float ToSingle (Char value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
+ }\r
+\r
+ public static float ToSingle (DateTime value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
+ }\r
\r
public static float ToSingle (decimal value) \r
{ \r
return (float)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static float ToSingle (sbyte value) \r
{ \r
return (float)value; \r
public static float ToSingle (string value, IFormatProvider provider) \r
{\r
return Single.Parse (value, provider);\r
- }\r
- \r
+ } \r
+\r
+ [CLSCompliant (false)]\r
public static float ToSingle (uint value) \r
{ \r
return (float)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static float ToSingle (ulong value) \r
{ \r
return (float)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static float ToSingle (ushort value) \r
{ \r
return (float)value; \r
}\r
\r
+ public static float ToSingle (object value)\r
+ {\r
+ return ToSingle (value, null);\r
+ }\r
+\r
+// [CLSCompliant (false)]\r
+ public static float ToSingle (object value, IFormatProvider provider)\r
+ {\r
+ if (value == null)\r
+ return 0;\r
+ return ((IConvertible) value).ToSingle (provider);\r
+ }\r
+\r
// ========== String Conversions ========== //\r
\r
public static string ToString (bool value) \r
{ \r
return value.ToString (); \r
}\r
+\r
+ public static string ToString (bool value, IFormatProvider provider)\r
+ {\r
+ return value.ToString (); // the same as ToString (bool).\r
+ }\r
\r
public static string ToString (byte value) \r
{ \r
return value.ToString (provider); \r
}\r
\r
+ public static string ToString (byte value, int toBase)\r
+ {\r
+ if (NotValidBase (toBase))\r
+ throw new ArgumentException ("toBase is not valid.");\r
+ \r
+ return ConvertToBase ((int) value, toBase);\r
+ }\r
+\r
public static string ToString (char value) \r
{ \r
return value.ToString (); \r
}\r
\r
+ public static string ToString (char value, IFormatProvider provider)\r
+ {\r
+ return value.ToString (); // the same as ToString (char)\r
+ }\r
+\r
public static string ToString (DateTime value) \r
{ \r
return value.ToString (); \r
return value.ToString (); \r
}\r
\r
+ public static string ToString (int value, int toBase)\r
+ {\r
+ if (NotValidBase (toBase))\r
+ throw new ArgumentException ("toBase is not valid.");\r
+ \r
+ return ConvertToBase ((int) value, toBase);\r
+ }\r
+\r
public static string ToString (int value, IFormatProvider provider) \r
{ \r
return value.ToString (provider); \r
return value.ToString (); \r
}\r
\r
+ public static string ToString (long value, int toBase)\r
+ {\r
+ if (NotValidBase (toBase))\r
+ throw new ArgumentException ("toBase is not valid.");\r
+ \r
+ return ConvertToBase (value, toBase);\r
+ }\r
+\r
public static string ToString (long value, IFormatProvider provider) \r
{ \r
return value.ToString (provider); \r
}\r
\r
+ public static string ToString (object value)\r
+ {\r
+ return ToString (value, null);\r
+ } \r
+\r
+ public static string ToString (object value, IFormatProvider provider)\r
+ {\r
+ if (value is IConvertible)\r
+ return ((IConvertible) value).ToString (provider);\r
+ else if (value != null)\r
+ return value.ToString ();\r
+ return String.Empty;\r
+ } \r
+\r
+ [CLSCompliant (false)]\r
public static string ToString (sbyte value) \r
{ \r
return value.ToString (); \r
}\r
\r
+ [CLSCompliant (false)] \r
public static string ToString (sbyte value, IFormatProvider provider) \r
{ \r
return value.ToString (provider); \r
return value.ToString (); \r
}\r
\r
+ public static string ToString (short value, int toBase)\r
+ {\r
+ if (NotValidBase (toBase))\r
+ throw new ArgumentException ("toBase is not valid.");\r
+ \r
+ return ConvertToBase ((int) value, toBase);\r
+ }\r
+\r
public static string ToString (short value, IFormatProvider provider) \r
{ \r
return value.ToString (provider); \r
return value;\r
}\r
\r
+ public static string ToString (string value, IFormatProvider provider)\r
+ {\r
+ return value; // provider is ignored.\r
+ }\r
+\r
+ [CLSCompliant (false)]\r
public static string ToString (uint value) \r
{ \r
return value.ToString (); \r
}\r
\r
+ [CLSCompliant (false)]\r
public static string ToString (uint value, IFormatProvider provider) \r
{ \r
return value.ToString (provider); \r
}\r
\r
+ [CLSCompliant (false)]\r
public static string ToString (ulong value) \r
{ \r
return value.ToString (); \r
}\r
\r
+ [CLSCompliant (false)]\r
public static string ToString (ulong value, IFormatProvider provider) \r
{ \r
return value.ToString (provider); \r
}\r
\r
+ [CLSCompliant (false)]\r
public static string ToString (ushort value) \r
{ \r
return value.ToString (); \r
}\r
\r
+ [CLSCompliant (false)]\r
public static string ToString (ushort value, IFormatProvider provider) \r
{ \r
return value.ToString (provider); \r
}\r
-\r
+ \r
// ========== UInt16 Conversions ========== //\r
\r
+ [CLSCompliant (false)]\r
public static ushort ToUInt16 (bool value) \r
{ \r
return (ushort)(value ? 1 : 0); \r
}\r
- \r
+\r
+ [CLSCompliant (false)]\r
public static ushort ToUInt16 (byte value) \r
{ \r
return (ushort)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static ushort ToUInt16 (char value) \r
{ \r
return (ushort)value; \r
}\r
- \r
+\r
+ [CLSCompliant (false)]\r
+ public static ushort ToUInt16 (DateTime value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
+ }\r
+\r
+ [CLSCompliant (false)]\r
public static ushort ToUInt16 (decimal value) \r
{ \r
if (value > UInt16.MaxValue || value < UInt16.MinValue) \r
return (ushort)(Math.Round (value)); \r
}\r
\r
+ [CLSCompliant (false)]\r
public static ushort ToUInt16 (double value) \r
{ \r
if (value > UInt16.MaxValue || value < UInt16.MinValue) \r
// Returned Even-Rounded\r
return (ushort)(Math.Round (value));\r
}\r
- \r
+\r
+ [CLSCompliant (false)]\r
public static ushort ToUInt16 (float value) \r
{ \r
if (value > UInt16.MaxValue || value < UInt16.MinValue) \r
return (ushort)(Math.Round ( (double)value));\r
}\r
\r
+ [CLSCompliant (false)]\r
public static ushort ToUInt16 (int value) \r
{ \r
if (value > UInt16.MaxValue || value < UInt16.MinValue) \r
\r
return (ushort)value; \r
}\r
- \r
+\r
+ [CLSCompliant (false)]\r
public static ushort ToUInt16 (long value) \r
{ \r
if (value > UInt16.MaxValue || value < UInt16.MinValue) \r
return (ushort)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static ushort ToUInt16 (sbyte value) \r
{ \r
if (value < UInt16.MinValue) \r
\r
return (ushort)value; \r
}\r
- \r
+\r
+ [CLSCompliant (false)]\r
public static ushort ToUInt16 (short value) \r
{ \r
if (value < UInt16.MinValue) \r
\r
return (ushort)value; \r
}\r
-\r
+ \r
+ [CLSCompliant (false)]\r
public static ushort ToUInt16 (string value) \r
{\r
return UInt16.Parse (value);\r
}\r
\r
+ [CLSCompliant (false)]\r
public static ushort ToUInt16 (string value, IFormatProvider provider) \r
{\r
return UInt16.Parse (value, provider);\r
}\r
- \r
+\r
+ [CLSCompliant (false)]\r
+ public static ushort ToUInt16 (string value, int fromBase) \r
+ {\r
+ return (ushort) ConvertFromBase (value, fromBase);\r
+ } \r
+\r
+ [CLSCompliant (false)]\r
public static ushort ToUInt16 (uint value) \r
{ \r
if (value > UInt16.MaxValue) \r
return (ushort)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static ushort ToUInt16 (ulong value) \r
{ \r
if (value > (ulong)UInt16.MaxValue) \r
return (ushort)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static ushort ToUInt16 (ushort value) \r
{ \r
return value; \r
}\r
\r
+ [CLSCompliant (false)]\r
+ public static ushort ToUInt16 (object value)\r
+ {\r
+ return ToUInt16 (value, null);\r
+ }\r
+\r
+ [CLSCompliant (false)]\r
+ public static ushort ToUInt16 (object value, IFormatProvider provider)\r
+ {\r
+ if (value == null)\r
+ return 0;\r
+ return ((IConvertible) value).ToUInt16 (provider);\r
+ }\r
+\r
// ========== UInt32 Conversions ========== //\r
\r
+ [CLSCompliant (false)]\r
public static uint ToUInt32 (bool value) \r
{ \r
return (uint)(value ? 1 : 0); \r
}\r
- \r
+\r
+ [CLSCompliant (false)]\r
public static uint ToUInt32 (byte value) \r
{ \r
return (uint)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static uint ToUInt32 (char value) \r
{ \r
return (uint)value; \r
}\r
- \r
+\r
+ [CLSCompliant (false)]\r
+ public static uint ToUInt32 (DateTime value)\r
+ {\r
+ throw new InvalidCastException ("This conversion is not supported.");\r
+ }\r
+ \r
+ [CLSCompliant (false)]\r
public static uint ToUInt32 (decimal value) \r
{ \r
if (value > UInt32.MaxValue || value < UInt32.MinValue) \r
return (uint)(Math.Round (value)); \r
}\r
\r
+ [CLSCompliant (false)]\r
public static uint ToUInt32 (double value) \r
{ \r
if (value > UInt32.MaxValue || value < UInt32.MinValue) \r
// Returned Even-Rounded\r
return (uint)(Math.Round (value)); \r
}\r
- \r
+\r
+ [CLSCompliant (false)]\r
public static uint ToUInt32 (float value) \r
{ \r
if (value > UInt32.MaxValue || value < UInt32.MinValue) \r
return (uint)(Math.Round ( (double)value));\r
}\r
\r
+ [CLSCompliant (false)]\r
public static uint ToUInt32 (int value) \r
{ \r
if (value < UInt32.MinValue) \r
\r
return (uint)value; \r
}\r
- \r
+\r
+ [CLSCompliant (false)]\r
public static uint ToUInt32 (long value) \r
{ \r
if (value > UInt32.MaxValue || value < UInt32.MinValue) \r
return (uint)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static uint ToUInt32 (sbyte value) \r
{ \r
if (value < UInt32.MinValue) \r
\r
return (uint)value; \r
}\r
- \r
+\r
+ [CLSCompliant (false)]\r
public static uint ToUInt32 (short value) \r
{ \r
if (value < UInt32.MinValue) \r
return (uint)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static uint ToUInt32 (string value) \r
{\r
return UInt32.Parse (value);\r
}\r
\r
+ [CLSCompliant (false)]\r
public static uint ToUInt32 (string value, IFormatProvider provider) \r
{\r
return UInt32.Parse (value, provider);\r
}\r
- \r
+\r
+ [CLSCompliant (false)]\r
+ public static uint ToUInt32 (string value, int fromBase)\r
+ {\r
+ return (uint) ConvertFromBase (value, fromBase);\r
+ }\r
+\r
+ [CLSCompliant (false)]\r
public static uint ToUInt32 (uint value) \r
{ \r
return value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static uint ToUInt32 (ulong value) \r
{ \r
if (value > UInt32.MaxValue) \r
return (uint)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static uint ToUInt32 (ushort value) \r
{ \r
return (uint)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
+ public static uint ToUInt32 (object value)\r
+ {\r
+ return ToUInt32 (value, null);\r
+ } \r
+\r
+ [CLSCompliant (false)]\r
+ public static uint ToUInt32 (object value, IFormatProvider provider)\r
+ {\r
+ if (value == null)\r
+ return 0;\r
+ return ((IConvertible) value).ToUInt32 (provider);\r
+ } \r
+ \r
+\r
// ========== UInt64 Conversions ========== //\r
\r
+ [CLSCompliant (false)]\r
public static ulong ToUInt64 (bool value) \r
{ \r
return (ulong)(value ? 1 : 0); \r
}\r
- \r
+\r
+ [CLSCompliant (false)]\r
public static ulong ToUInt64 (byte value) \r
{ \r
return (ulong)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static ulong ToUInt64 (char value) \r
{ \r
return (ulong)value; \r
}\r
- \r
+\r
+ [CLSCompliant (false)]\r
+ public static ulong ToUInt64 (DateTime value)\r
+ {\r
+ throw new InvalidCastException ("The conversion is not supported.");\r
+ }\r
+\r
+ [CLSCompliant (false)]\r
public static ulong ToUInt64 (decimal value) \r
{ \r
if (value > UInt64.MaxValue || value < UInt64.MinValue) \r
return (ulong)(Math.Round (value)); \r
}\r
\r
+ [CLSCompliant (false)]\r
public static ulong ToUInt64 (double value) \r
{ \r
if (value > UInt64.MaxValue || value < UInt64.MinValue) \r
// Returned Even-Rounded\r
return (ulong)(Math.Round (value)); \r
}\r
- \r
+ \r
+ [CLSCompliant (false)] \r
public static ulong ToUInt64 (float value) \r
{ \r
if (value > UInt64.MaxValue || value < UInt64.MinValue) \r
// Returned Even-Rounded, pass as a double to Math\r
return (ulong)(Math.Round ( (double)value));\r
}\r
-\r
+ \r
+ [CLSCompliant (false)]\r
public static ulong ToUInt64 (int value) \r
{ \r
if (value < (int)UInt64.MinValue) \r
\r
return (ulong)value; \r
}\r
- \r
+ \r
+ [CLSCompliant (false)]\r
public static ulong ToUInt64 (long value) \r
{ \r
if (value < (long)UInt64.MinValue) \r
return (ulong)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static ulong ToUInt64 (sbyte value) \r
{ \r
if (value < (sbyte)UInt64.MinValue) \r
\r
return (ulong)value; \r
}\r
- \r
+ \r
+ [CLSCompliant (false)] \r
public static ulong ToUInt64 (short value) \r
{ \r
if (value < (short)UInt64.MinValue) \r
return (ulong)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static ulong ToUInt64 (string value) \r
{\r
return UInt64.Parse (value);\r
}\r
\r
+ [CLSCompliant (false)]\r
public static ulong ToUInt64 (string value, IFormatProvider provider) \r
{\r
return UInt64.Parse (value, provider);\r
}\r
- \r
+\r
+ [CLSCompliant (false)]\r
+ public static ulong ToUInt64 (string value, int fromBase)\r
+ {\r
+ return (ulong) ConvertFromBase (value, fromBase);\r
+ } \r
+\r
+ [CLSCompliant (false)]\r
public static ulong ToUInt64 (uint value) \r
{ \r
return (ulong)value; \r
}\r
\r
+ [CLSCompliant (false)]\r
public static ulong ToUInt64 (ulong value) \r
{ \r
return value; \r
}\r
-\r
+ \r
+ [CLSCompliant (false)]\r
public static ulong ToUInt64 (ushort value) \r
{ \r
return (ulong)value; \r
}\r
\r
- // ========== Conversion / Helper Fucntions ========== //\r
+ [CLSCompliant (false)]\r
+ public static ulong ToUInt64 (object value)\r
+ {\r
+ return ToUInt64 (value, null);\r
+ } \r
+\r
+ [CLSCompliant (false)]\r
+ public static ulong ToUInt64 (object value, IFormatProvider provider)\r
+ {\r
+ if (value == null)\r
+ return 0;\r
+ return ((IConvertible) value).ToUInt64 (provider);\r
+ } \r
+ \r
+\r
+ // ========== Conversion / Helper Functions ========== //\r
\r
public static object ChangeType (object value, Type conversionType)\r
{\r
{\r
Type conversionType = conversionTable [(int)typeCode];\r
return ToType (value, conversionType, provider);\r
- } \r
+ }\r
+\r
+ private static bool NotValidBase (int value)\r
+ {\r
+ if ((value == 2) || (value == 8) ||\r
+ (value == 10) || (value == 16))\r
+ return false;\r
+ \r
+ return true;\r
+ }\r
+\r
+ private static int ConvertFromBase (string value, int fromBase)\r
+ {\r
+ if (NotValidBase (fromBase))\r
+ throw new ArgumentException ("fromBase is not valid.");\r
+\r
+ int chars = 0;\r
+ int result = 0;\r
+ int digitValue;\r
+\r
+ foreach (char c in value) {\r
+ if (Char.IsNumber (c))\r
+ digitValue = c - '0';\r
+ else if (Char.IsLetter (c))\r
+ digitValue = Char.ToLower(c) - 'a' + 10;\r
+ else\r
+ throw new FormatException ("This is an invalid string: " + value);\r
+\r
+ if (digitValue >= fromBase)\r
+ throw new FormatException ("the digits are invalid.");\r
+\r
+ result = (fromBase) * result + digitValue;\r
+ chars ++;\r
+ }\r
+\r
+ if (chars == 0)\r
+ throw new FormatException ("Could not find any digits.");\r
+\r
+ if (result > Int32.MaxValue || result < Int32.MinValue)\r
+ throw new OverflowException ("There is an overflow.");\r
+ \r
+ return result;\r
+ }\r
+\r
+ private static long ConvertFromBase64 (string value, int fromBase)\r
+ {\r
+ if (NotValidBase (fromBase))\r
+ throw new ArgumentException ("fromBase is not valid.");\r
+\r
+ int chars = 0;\r
+ int digitValue;\r
+ long result = 0;\r
+\r
+ foreach (char c in value) {\r
+ if (Char.IsNumber (c))\r
+ digitValue = c - '0';\r
+ else if (Char.IsLetter (c))\r
+ digitValue = Char.ToLower(c) - 'a' + 10;\r
+ else\r
+ throw new FormatException ("This is an invalid string: " + value);\r
+\r
+ if (digitValue >= fromBase)\r
+ throw new FormatException ("the digits are invalid.");\r
+\r
+ result = (fromBase) * result + digitValue;\r
+ chars ++;\r
+ }\r
+\r
+ if (chars == 0)\r
+ throw new FormatException ("Could not find any digits.");\r
+\r
+ if (result > Int64.MaxValue || result < Int64.MinValue)\r
+ throw new OverflowException ("There is an overflow.");\r
+ \r
+ return result;\r
+ }\r
+\r
+ private static string ConvertToBase (int value, int toBase)\r
+ {\r
+ StringBuilder sb = new StringBuilder ();\r
+ BuildConvertedString (sb, value, toBase);\r
+ return sb.ToString ();\r
+ }\r
+\r
+ private static string ConvertToBase (long value, int toBase)\r
+ {\r
+ StringBuilder sb = new StringBuilder ();\r
+ BuildConvertedString64 (sb, value, toBase);\r
+ return sb.ToString ();\r
+ }\r
+ \r
+\r
+ internal static void BuildConvertedString (StringBuilder sb, int value, int toBase)\r
+ {\r
+ int divided = value / toBase;\r
+ int reminder = value % toBase; \r
+\r
+ if (divided > 0)\r
+ BuildConvertedString (sb, divided, toBase);\r
+ \r
+ if (reminder >= 10)\r
+ sb.Append ((char) (reminder + 'a' - 10));\r
+ else\r
+ sb.Append ((char) (reminder + '0'));\r
+ }\r
\r
+ internal static void BuildConvertedString64 (StringBuilder sb, long value, int toBase)\r
+ {\r
+ long divided = value / toBase;\r
+ long reminder = value % toBase; \r
+\r
+ if (divided > 0)\r
+ BuildConvertedString64 (sb, divided, toBase);\r
+ \r
+ if (reminder >= 10)\r
+ sb.Append ((char) (reminder + 'a' - 10));\r
+ else\r
+ sb.Append ((char) (reminder + '0'));\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
private static Type[] conversionTable = {\r
// Valid ICovnertible Types\r
- typeof (Boolean), // 0 TypeCode.Boolean\r
- typeof (Byte), // 1 TypeCode.Byte\r
- typeof (Char), // 2 TypeCode.Char\r
- typeof (DateTime), // 3 TypeCode.DateTime\r
- typeof (Decimal), // 4 TypeCode.Decimal\r
- typeof (Double), // 5 TypeCode.Double\r
- typeof (Int16), // 6 TypeCode.Int16\r
- typeof (Int32), // 7 TypeCode.Int32\r
- typeof (Int64), // 8 TypeCode.Int64\r
- typeof (SByte), // 9 TypeCode.Sbyte\r
- typeof (Single), // 10 TypeCode.Single\r
- typeof (String), // 11 TypeCode.String\r
- typeof (UInt16), // 12 TypeCode.UInt16\r
- typeof (UInt32), // 13 TypeCode.UInt32\r
- typeof (UInt64), // 14 TypeCode.UInt64\r
- \r
- // Invalid IConvertible Interface Types\r
- typeof (Object) // 15 TypeCode.Object\r
+ null, // 0 empty\r
+ typeof (object), // 1 TypeCode.Object\r
+ typeof (DBNull), // 2 TypeCode.DBNull\r
+ typeof (Boolean), // 3 TypeCode.Boolean\r
+ typeof (Char), // 4 TypeCode.Char\r
+ typeof (SByte), // 5 TypeCode.SByte\r
+ typeof (Byte), // 6 TypeCode.Byte\r
+ typeof (Int16), // 7 TypeCode.Int16\r
+ typeof (UInt16), // 8 TypeCode.UInt16\r
+ typeof (Int32), // 9 TypeCode.Int32\r
+ typeof (UInt32), // 10 TypeCode.UInt32\r
+ typeof (Int64), // 11 TypeCode.Int64\r
+ typeof (UInt64), // 12 TypeCode.UInt64\r
+ typeof (Single), // 13 TypeCode.Single\r
+ typeof (Double), // 14 TypeCode.Double\r
+ typeof (Decimal), // 15 TypeCode.Decimal\r
+ typeof (DateTime), // 16 TypeCode.DateTime\r
+ null, // 17 null.\r
+ typeof (String), // 18 TypeCode.String\r
};\r
\r
// Function to convert an object to another type and return\r
internal static object ToType (object value, Type conversionType, \r
IFormatProvider provider) \r
{\r
+ if (value == null && conversionType == null)\r
+ return null;\r
+ \r
if (value == null)\r
- throw new ArgumentException (Locale.GetText (\r
- "Invalid conversion from null value"));\r
-\r
+ throw new NullReferenceException ("Value is null.");\r
+ \r
if (value is IConvertible) {\r
- IConvertible convertValue = (IConvertible)value;\r
-\r
- if (conversionType == conversionTable[0]) {\r
- // 0 TypeCode.Boolean\r
- return (object)(convertValue.ToBoolean (provider));\r
+ IConvertible convertValue = (IConvertible) value;\r
\r
- } else if (conversionType == conversionTable[1]) {\r
- // 1 TypeCode.Byte\r
- return (object)(convertValue.ToByte (provider));\r
- \r
- } else if (conversionType == conversionTable[2]) {\r
- // 2 TypeCode.Char\r
- return (object)(convertValue.ToChar (provider));\r
- \r
- } else if (conversionType == conversionTable[3]) {\r
- // 3 TypeCode.DateTime\r
- return (object)(convertValue.ToDateTime (provider));\r
+ if (conversionType == conversionTable[0]) // 0 Empty\r
+ throw new ArgumentNullException ();\r
+ \r
+ else if (conversionType == conversionTable[1]) // 1 TypeCode.Object\r
+ return (object) value;\r
+ \r
+ else if (conversionType == conversionTable[2]) // 2 TypeCode.DBNull\r
+ throw new InvalidCastException (); // It's not IConvertible\r
\r
- } else if (conversionType == conversionTable[4]) {\r
- // 4 TypeCode.Decimal\r
- return (object)(convertValue.ToDecimal (provider));\r
+ else if (conversionType == conversionTable[3]) // 3 TypeCode.Boolean\r
+ return (object) convertValue.ToBoolean (provider);\r
+ \r
+ else if (conversionType == conversionTable[4]) // 4 TypeCode.Char\r
+ return (object) convertValue.ToChar (provider);\r
\r
- } else if (conversionType == conversionTable[5]) {\r
- // 5 TypeCode.Double\r
- return (object)(convertValue.ToDouble (provider));\r
+ else if (conversionType == conversionTable[5]) // 5 TypeCode.SByte\r
+ return (object) convertValue.ToSByte (provider);\r
\r
- } else if (conversionType == conversionTable[6]) {\r
- // 6 TypeCode.Int16\r
- return (object)(convertValue.ToInt16 (provider));\r
- \r
- } else if (conversionType == conversionTable[7]) {\r
- // 7 TypeCode.Int32\r
- return (object)(convertValue.ToInt32 (provider));\r
- \r
- } else if (conversionType == conversionTable[8]) {\r
- // 8 TypeCode.Int64\r
- return (object)(convertValue.ToInt64 (provider));\r
- \r
- } else if (conversionType == conversionTable[9]) {\r
- // 9 TypeCode.Sbyte\r
- return (object)(convertValue.ToSByte (provider));\r
+ else if (conversionType == conversionTable[6]) // 6 TypeCode.Byte\r
+ return (object) convertValue.ToByte (provider);\r
+ \r
+ else if (conversionType == conversionTable[7]) // 7 TypeCode.Int16\r
+ return (object) convertValue.ToInt16 (provider);\r
+ \r
+ else if (conversionType == conversionTable[8]) // 8 TypeCode.UInt16\r
+ return (object) convertValue.ToUInt16 (provider);\r
\r
- } else if (conversionType == conversionTable[10]) {\r
- // 10 TypeCode.Single\r
- return (object)(convertValue.ToSingle (provider));\r
+ else if (conversionType == conversionTable[9]) // 9 TypeCode.Int32\r
+ return (object) convertValue.ToInt32 (provider);\r
+ \r
+ else if (conversionType == conversionTable[10]) // 10 TypeCode.UInt32\r
+ return (object) convertValue.ToUInt32 (provider);\r
\r
- } else if (conversionType == conversionTable[11]) {\r
- // 11 TypeCode.String\r
- return (object)(convertValue.ToString (provider));\r
+ else if (conversionType == conversionTable[11]) // 11 TypeCode.Int64\r
+ return (object) convertValue.ToInt64 (provider);\r
\r
- } else if (conversionType == conversionTable[12]) { \r
- // 12 TypeCode.UInt16\r
- return (object)(convertValue.ToUInt16 (provider));\r
+ else if (conversionType == conversionTable[12]) // 12 TypeCode.UInt64\r
+ return (object) convertValue.ToUInt64 (provider);\r
\r
- } else if (conversionType == conversionTable[13]) {\r
- // 13 TypeCode.UInt32\r
- return (object)(convertValue.ToUInt32 (provider));\r
+ else if (conversionType == conversionTable[13]) // 13 TypeCode.Single\r
+ return (object) convertValue.ToSingle (provider);\r
\r
- } else if (conversionType == conversionTable[14]) {\r
- // 14 TypeCode.UInt64\r
- return (object)(convertValue.ToUInt64 (provider));\r
-\r
- } else if (conversionType == conversionTable[15]) {\r
- // 15 TypeCode.Object\r
- return (object)(value);\r
-\r
- } else { \r
- // Not in the conversion table\r
- throw new InvalidCastException (Locale.GetText (\r
- "Unknown target conversion type"));\r
- }\r
- } else {\r
- // Value is not IConvertible\r
- throw new ArgumentException (Locale.GetText (\r
- "Value is not a convertible object: "+ value.GetType().ToString()+" to "+conversionType.ToString()));\r
- }\r
+ else if (conversionType == conversionTable[14]) // 14 TypeCode.Double\r
+ return (object) convertValue.ToDouble (provider);\r
+\r
+ else if (conversionType == conversionTable[15]) // 15 TypeCode.Decimal\r
+ return (object) convertValue.ToDecimal (provider);\r
+\r
+ else if (conversionType == conversionTable[16]) // 16 TypeCode.DateTime\r
+ return (object) convertValue.ToDateTime (provider);\r
+ \r
+ else if (conversionType == conversionTable[18]) // 18 TypeCode.String\r
+ return (object) convertValue.ToString (provider);\r
+ else\r
+ throw new ArgumentException (Locale.GetText ("Unknown target conversion type"));\r
+ } else\r
+ // Not in the conversion table\r
+ throw new InvalidCastException ((Locale.GetText (\r
+ "Value is not a convertible object: " + value.GetType().ToString() + " to " + conversionType.FullName)));\r
}\r
}\r
}\r
-\r
-\r
-\r
-\r