public object EvaluatePostOrPrefix(ref object v) { int num; double num5; IConvertible iConvertible = Microsoft.JScript.Convert.GetIConvertible(v); switch (Microsoft.JScript.Convert.GetTypeCode(v, iConvertible)) { case TypeCode.Empty: v = (double)1.0 / (double)0.0; return(v); case TypeCode.DBNull: v = 0; return(this.DoOp(0)); case TypeCode.Boolean: case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: v = num = iConvertible.ToInt32(null); return(this.DoOp(num)); case TypeCode.Char: num = iConvertible.ToInt32(null); return(((IConvertible)this.DoOp(num)).ToChar(null)); case TypeCode.UInt32: uint num2; v = num2 = iConvertible.ToUInt32(null); return(this.DoOp(num2)); case TypeCode.Int64: long num3; v = num3 = iConvertible.ToInt64(null); return(this.DoOp(num3)); case TypeCode.UInt64: ulong num4; v = num4 = iConvertible.ToUInt64(null); return(this.DoOp(num4)); case TypeCode.Single: case TypeCode.Double: v = num5 = iConvertible.ToDouble(null); return(this.DoOp(num5)); } MethodInfo @operator = this.GetOperator(v.GetType()); if (@operator != null) { return(@operator.Invoke(null, BindingFlags.Default, JSBinder.ob, new object[] { v }, null)); } v = num5 = Microsoft.JScript.Convert.ToNumber(v, iConvertible); return(this.DoOp(num5)); }
private static IEnumerable <byte> GetBytesFromConvertible(Type type, IConvertible value, uint defaultStringLength) { IEnumerable <byte> varValueBytes = null; if (value == null) { return(null); } switch (value.GetTypeCode()) { case TypeCode.Boolean: varValueBytes = BitConverter.GetBytes(value.ToBoolean(null)); break; case TypeCode.Byte: varValueBytes = new byte[] { value.ToByte(null) }; break; case TypeCode.Char: varValueBytes = BitConverter.GetBytes(value.ToChar(null)); break; case TypeCode.Int16: varValueBytes = BitConverter.GetBytes(value.ToInt16(null)); break; case TypeCode.Int32: varValueBytes = BitConverter.GetBytes(value.ToInt32(null)); break; case TypeCode.Int64: varValueBytes = BitConverter.GetBytes(value.ToInt64(null)); break; case TypeCode.UInt16: varValueBytes = BitConverter.GetBytes(value.ToUInt16(null)); break; case TypeCode.UInt32: varValueBytes = BitConverter.GetBytes(value.ToUInt32(null)); break; case TypeCode.UInt64: varValueBytes = BitConverter.GetBytes(value.ToUInt64(null)); break; case TypeCode.Single: varValueBytes = BitConverter.GetBytes(value.ToSingle(null)); break; case TypeCode.Double: varValueBytes = BitConverter.GetBytes(value.ToDouble(null)); break; case TypeCode.DateTime: varValueBytes = BitConverter.GetBytes(value.ToInt32(null)); break; case TypeCode.String: varValueBytes = value.ToString().ToAdsBytes(); break; case TypeCode.Object: if (Type.Equals(typeof(Date), type)) { varValueBytes = BitConverter.GetBytes(value.ToInt32(null)); } if (Type.Equals(typeof(Time), type)) { varValueBytes = BitConverter.GetBytes(value.ToInt32(null)); } break; } return(varValueBytes); }
public IComparable EvaluateComparable(IEvaluateContext context) { IConvertible result = Evaluate(context); if (result == null) { throw new LoadDataException("Could not evaluate " + _source); } if (result is EnumValue) { return((EnumValue)result); } if (result.GetTypeCode() == TypeCode.String) { return(result.ToString(CultureInfo.CurrentCulture)); } else if (result.GetTypeCode() == TypeCode.UInt32) { uint value = result.ToUInt32(CultureInfo.CurrentCulture); return((int)value); } try { return(result.ToInt32(CultureInfo.CurrentCulture)); } catch (OverflowException e) { throw new LoadDataException(e.Message); } }
public static void Main() { IConvertible letter = Letter.B; Console.WriteLine(letter.ToInt32(null)); Console.WriteLine(letter.ToInt64(null)); }
static int GetInt(object value) { IConvertible val = (IConvertible)value; int cast = val.ToInt32(null); return(cast); }
public bool PosTest3() { bool retVal = true; // Add your scenario description here TestLibrary.TestFramework.BeginScenario("PosTest3:Check zero "); try { Int32 i1 = 0; IConvertible Icon1 = (IConvertible)i1; if (Icon1.ToInt32(null) != i1) { TestLibrary.TestFramework.LogError("005", "The result is not the value as expected"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("006", "Unexpected exception: " + e); retVal = false; } return(retVal); }
public bool PosTest3() { bool retVal = true; CultureInfo myculture = new CultureInfo("el-GR"); IFormatProvider provider = myculture.NumberFormat; TestLibrary.TestFramework.BeginScenario("PosTest3:The random sbyte IConvertible To Int32 1"); try { sbyte sbyteVal = (sbyte)(this.GetInt32(0, 128)); IConvertible iConvert = (IConvertible)(sbyteVal); Int32 Int32Val = iConvert.ToInt32(provider); if (Int32Val != (Int32)(sbyteVal)) { TestLibrary.TestFramework.LogError("005", "the ActualResult is not the ExpectResult"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("006", "Unexpected exception: " + e); retVal = false; } return(retVal); }
public static bool IsNumericZero(ICompileTimeConstant constExpression) { IConvertible /*?*/ ic = constExpression.Value as IConvertible; if (ic == null) { return(false); } switch (ic.GetTypeCode()) { case System.TypeCode.SByte: return(ic.ToSByte(null) == 0); case System.TypeCode.Int16: return(ic.ToInt16(null) == 0); case System.TypeCode.Int32: return(ic.ToInt32(null) == 0); case System.TypeCode.Int64: return(ic.ToInt64(null) == 0); case System.TypeCode.Byte: return(ic.ToByte(null) == 0); case System.TypeCode.UInt16: return(ic.ToUInt16(null) == 0); case System.TypeCode.UInt32: return(ic.ToUInt32(null) == 0); case System.TypeCode.UInt64: return(ic.ToUInt64(null) == 0); case System.TypeCode.Single: return(ic.ToSingle(null) == 0); case System.TypeCode.Double: return(ic.ToDouble(null) == 0); case System.TypeCode.Decimal: return(ic.ToDecimal(null) == 0); } return(false); }
public void Substract(IConvertible value) { if (typeof(T) == typeof(byte)) { Value = (T)(object)(Value.ToByte(null) - value.ToByte(null)); } if (typeof(T) == typeof(sbyte)) { Value = (T)(object)(Value.ToSByte(null) - value.ToSByte(null)); } if (typeof(T) == typeof(short)) { Value = (T)(object)(Value.ToInt16(null) - value.ToInt16(null)); } if (typeof(T) == typeof(ushort)) { Value = (T)(object)(Value.ToUInt16(null) - value.ToUInt16(null)); } if (typeof(T) == typeof(int)) { Value = (T)(object)(Value.ToInt32(null) - value.ToInt32(null)); } if (typeof(T) == typeof(uint)) { Value = (T)(object)(Value.ToUInt32(null) - value.ToUInt32(null)); } if (typeof(T) == typeof(long)) { Value = (T)(object)(Value.ToInt64(null) - value.ToInt64(null)); } if (typeof(T) == typeof(ulong)) { Value = (T)(object)(Value.ToUInt64(null) - value.ToUInt64(null)); } }
/// <summary> /// 不能为0 /// </summary> /// <param name="obj"></param> /// <param name="message"></param> public static void IsZero(IConvertible obj, string message) { if (obj.ToInt32() == 0) { throw new Exception(message); } }
public static string GetDescription(Type enumType, IConvertible value) { if (enumType.BaseType == typeof(Enum)) { var val = value.ToInt32(CultureInfo.InvariantCulture); var enumName = enumType.GetEnumName(val); if (enumName == null) { return(string.Empty); } var memInfo = enumType.GetMember(enumName); var descriptionAttribute = memInfo[0] .GetCustomAttributes(typeof(DescriptionAttribute), false) .FirstOrDefault() as DescriptionAttribute; if (descriptionAttribute != null) { return(descriptionAttribute.Description); } } return(null); // could also return string.Empty }
public static bool IsIntegralZero(ICompileTimeConstant constExpression) { IConvertible /*?*/ ic = constExpression.Value as IConvertible; if (ic == null) { return(false); } switch (ic.GetTypeCode()) { case System.TypeCode.SByte: return(ic.ToSByte(null) == 0); case System.TypeCode.Int16: return(ic.ToInt16(null) == 0); case System.TypeCode.Int32: return(ic.ToInt32(null) == 0); case System.TypeCode.Int64: return(ic.ToInt64(null) == 0); case System.TypeCode.Byte: return(ic.ToByte(null) == 0); case System.TypeCode.UInt16: return(ic.ToUInt16(null) == 0); case System.TypeCode.UInt32: return(ic.ToUInt32(null) == 0); case System.TypeCode.UInt64: return(ic.ToUInt64(null) == 0); case System.TypeCode.Boolean: return(!ic.ToBoolean(null)); } return(false); }
public bool PosTest2() { bool retVal = true; CultureInfo myculture = new CultureInfo("el-GR"); IFormatProvider provider = myculture.NumberFormat; TestLibrary.TestFramework.BeginScenario("PosTest2:The sbyte MinValue IConvertible To Int32"); try { sbyte sbyteVal = sbyte.MinValue; IConvertible iConvert = (IConvertible)(sbyteVal); Int32 Int32Val = iConvert.ToInt32(provider); if (Int32Val != -128) { TestLibrary.TestFramework.LogError("003", "the ActualResult is not the ExpectResult"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e); retVal = false; } return(retVal); }
private static bool EqualityOperator(object lhs, TypeCode lhsTypeCode, object rhs, TypeCode rhsTypeCode) { IConvertible convertible = (IConvertible)lhs; IConvertible convertible2 = (IConvertible)rhs; switch (GetConvertTypeCode(lhsTypeCode, rhsTypeCode)) { case TypeCode.Decimal: return(convertible.ToDecimal(null) == convertible2.ToDecimal(null)); case TypeCode.Double: return(convertible.ToDouble(null) == convertible2.ToDouble(null)); case TypeCode.Single: return(convertible.ToSingle(null) == convertible2.ToSingle(null)); case TypeCode.UInt64: return(convertible.ToUInt64(null) == convertible2.ToUInt64(null)); case TypeCode.Int64: return(convertible.ToInt64(null) == convertible2.ToInt64(null)); case TypeCode.UInt32: return(convertible.ToUInt32(null) == convertible2.ToUInt32(null)); default: return(convertible.ToInt32(null) == convertible2.ToInt32(null)); } }
private object PromoteNumericArgument(Type type, object argument) { IConvertible convertible = (IConvertible)argument; switch (Type.GetTypeCode(type)) { case TypeCode.Byte: return(convertible.ToByte(null)); case TypeCode.SByte: return(convertible.ToSByte(null)); case TypeCode.Int16: return(convertible.ToInt16(null)); case TypeCode.Int32: return(convertible.ToInt32(null)); case TypeCode.Int64: return(convertible.ToInt64(null)); case TypeCode.UInt16: return(convertible.ToUInt16(null)); case TypeCode.UInt32: return(convertible.ToUInt32(null)); case TypeCode.UInt64: return(convertible.ToUInt64(null)); case TypeCode.Single: return(convertible.ToSingle(null)); case TypeCode.Double: return(convertible.ToDouble(null)); case TypeCode.Boolean: return(convertible.ToBoolean(null)); case TypeCode.Decimal: return(convertible.ToDecimal(null)); case TypeCode.Char: return(convertible.ToChar(null)); } throw new ArgumentException(); }
// Slower public static string ToStringFast_Enum_Only <T>(this T e) where T : struct, Enum { IConvertible cv = (IConvertible)e; return(EnumStrings <T> .GetEnumString(cv.ToInt32(CultureInfo.InvariantCulture))); }
static int Diff(IConvertible val1, IConvertible val2) { ulong diff; switch (val1.GetTypeCode()) { case TypeCode.UInt64: diff = val2.ToUInt64(null) - val1.ToUInt64(null); break; case TypeCode.Int64: diff = (ulong)(val2.ToInt64(null) - val1.ToInt64(null)); break; case TypeCode.UInt32: diff = val2.ToUInt32(null) - val1.ToUInt32(null); break; default: diff = (ulong)(val2.ToInt32(null) - val1.ToInt32(null)); break; } if (diff >= int.MaxValue) { return(int.MaxValue); } else { return((int)diff); } }
// Convert an object into an integer value. public static int FromObject(Object Value) { #if !ECMA_COMPAT if (Value != null) { IConvertible ic = (Value as IConvertible); if (ic != null) { if (ic.GetTypeCode() != TypeCode.String) { return(ic.ToInt32(null)); } else { return(FromString(ic.ToString(null))); } } else { throw new InvalidCastException (String.Format (S._("VB_InvalidCast"), Value.GetType(), "System.ToInt32")); } } else { return(0); } #else return(checked ((int)(LongType.FromObject(Value)))); #endif }
/////////////////////////////////////////////////////////////////////////////////////////////// public static bool ToInteger(Number number, ref int value) { bool result = false; try { if (number != null) { if (number.IsInteger()) { value = (int)number.Value; result = true; } else { IConvertible convertible = number.Value as IConvertible; if (convertible != null) { value = convertible.ToInt32(null); result = true; } } } } catch { // do nothing. } return(result); }
public static bool IsConstantIntOrNull(this BoxedExpression e, out int res) { res = 0; if (e.IsConstant) { IConvertible convertible = e.Constant as IConvertible; if (convertible != null) { if (e.Constant is string || e.Constant is float || e.Constant is double) { return(false); } try { res = convertible.ToInt32(null); return(true); } catch { } } if (e.Constant == null) { return(true); } } return(false); }
public bool PosTest2() { bool retVal = true; // Add your scenario description here TestLibrary.TestFramework.BeginScenario("PosTest2: Convert a random Double( > 0.5 ) to int32"); try { Double i1; do { i1 = (Double)TestLibrary.Generator.GetDouble(-55); }while (i1 <= 0.5D); IConvertible Icon1 = (IConvertible)i1; if (Icon1.ToInt32(null) != 1) { TestLibrary.TestFramework.LogError("002.1", "The result is not the value as expected"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("002.1", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
protected override void HandleHitTest(Graphics g, OlvListViewHitTestInfo hti, int x, int y) { IConvertible aspect = base.Aspect as IConvertible; if (aspect != null) { int num = aspect.ToInt32(NumberFormatInfo.InvariantInfo); Point location = base.Bounds.Location; foreach (int num2 in this.keysInOrder) { if ((num & num2) == num2) { Image image = this.GetImage(this.imageMap[num2]); if (image != null) { Rectangle rectangle = new Rectangle(location, image.Size); if (rectangle.Contains(x, y)) { hti.UserData = num2; break; } location.X += image.Width + base.Spacing; } } } } }
public static string GetDescription <U>(this IConvertible e) where U : class, IDescription { if (e is Enum) { Type type = e.GetType(); Array values = Enum.GetValues(type); foreach (int val in values) { if (val == e.ToInt32(CultureInfo.InvariantCulture)) { var memInfo = type.GetMember(type.GetEnumName(val)); var descriptionAttribute = memInfo[0] .GetCustomAttributes(typeof(U), false) .FirstOrDefault() as U; if (descriptionAttribute != null) { return(descriptionAttribute.Description); } } } } return(null); // could also return string.Empty }
private void AppendInteger(IConvertible value) { switch (value.GetTypeCode()) { case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: this.sb.Append(value.ToInt32(null)); return; case TypeCode.Byte: case TypeCode.UInt16: case TypeCode.UInt32: this.sb.Append(value.ToUInt32(null)); return; case TypeCode.Int64: this.sb.Append(value.ToInt64(null)); return; case TypeCode.UInt64: this.sb.Append(value.ToUInt64(null)); return; default: return; } }
public bool PosTest4() { bool retVal = true; // Add your scenario description here TestLibrary.TestFramework.BeginScenario("PosTest4: Check a random Int32 number "); try { Int32 i1 = TestLibrary.Generator.GetInt32(-55); IConvertible Icon1 = (IConvertible)i1; if (Icon1.ToInt32(null) != i1) { TestLibrary.TestFramework.LogError("007", string.Format("The result is not the value {0} as expected", i1)); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("008", "Unexpected exception: " + e); retVal = false; } return(retVal); }
public static bool IsIntegralMinusOne(ICompileTimeConstant constExpression) { IConvertible /*?*/ ic = constExpression.Value as IConvertible; if (ic == null) { return(false); } switch (ic.GetTypeCode()) { case System.TypeCode.SByte: return(ic.ToSByte(null) == -1); case System.TypeCode.Int16: return(ic.ToInt16(null) == -1); case System.TypeCode.Int32: return(ic.ToInt32(null) == -1); case System.TypeCode.Int64: return(ic.ToInt64(null) == -1); case System.TypeCode.Byte: return(ic.ToByte(null) == byte.MaxValue); case System.TypeCode.UInt16: return(ic.ToUInt16(null) == ushort.MaxValue); case System.TypeCode.UInt32: return(ic.ToUInt32(null) == uint.MaxValue); case System.TypeCode.UInt64: return(ic.ToUInt64(null) == ulong.MaxValue); } return(false); }
public bool PosTest2() { bool retVal = true; CultureInfo myculture = new CultureInfo("el-GR"); IFormatProvider provider = myculture.NumberFormat; TestLibrary.TestFramework.BeginScenario("PosTest2:The Int64 value which in the range of Int32 IConvertible To Int32 2"); try { long int64A = Int32.MinValue; IConvertible iConvert = (IConvertible)(int64A); int int32A = iConvert.ToInt32(provider); if (int32A != int64A) { TestLibrary.TestFramework.LogError("003", "the ActualResult is not the ExpectResult"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e); retVal = false; } return(retVal); }
public void ValuesAreConvertible() { RedisValue val = 123; object o = val; byte[] blob = (byte[])Convert.ChangeType(o, typeof(byte[])); Assert.AreEqual(3, blob.Length); Assert.AreEqual((byte)'1', blob[0]); Assert.AreEqual((byte)'2', blob[1]); Assert.AreEqual((byte)'3', blob[2]); Assert.AreEqual((double)123, Convert.ToDouble(o)); IConvertible c = (IConvertible)o; Assert.AreEqual((short)123, c.ToInt16(CultureInfo.InvariantCulture)); Assert.AreEqual((int)123, c.ToInt32(CultureInfo.InvariantCulture)); Assert.AreEqual((long)123, c.ToInt64(CultureInfo.InvariantCulture)); Assert.AreEqual((float)123, c.ToSingle(CultureInfo.InvariantCulture)); Assert.AreEqual("123", c.ToString(CultureInfo.InvariantCulture)); Assert.AreEqual((double)123, c.ToDouble(CultureInfo.InvariantCulture)); Assert.AreEqual((decimal)123, c.ToDecimal(CultureInfo.InvariantCulture)); Assert.AreEqual((ushort)123, c.ToUInt16(CultureInfo.InvariantCulture)); Assert.AreEqual((uint)123, c.ToUInt32(CultureInfo.InvariantCulture)); Assert.AreEqual((ulong)123, c.ToUInt64(CultureInfo.InvariantCulture)); blob = (byte[])c.ToType(typeof(byte[]), CultureInfo.InvariantCulture); Assert.AreEqual(3, blob.Length); Assert.AreEqual((byte)'1', blob[0]); Assert.AreEqual((byte)'2', blob[1]); Assert.AreEqual((byte)'3', blob[2]); }
private static object ConvertTo(string value, Type t) { if (t.IsEnum) { return(Enum.Parse(t, value)); } TypeCode c = Type.GetTypeCode(t); if (c == TypeCode.String) { return(value); } IConvertible valueConvert = value as IConvertible; switch (c) { case TypeCode.Boolean: return(valueConvert.ToBoolean(null)); case TypeCode.Int32: return(valueConvert.ToInt32(null)); case TypeCode.Double: return(valueConvert.ToDouble(null)); case TypeCode.String: return(value); } return(null); }
// Slower public static bool TryToStringFast_Enum_Only <T>(this T e, [MaybeNullWhen(false)] out string str) where T : struct, Enum { IConvertible cv = (IConvertible)e; return(EnumStrings <T> .TryGetEnumString(cv.ToInt32(CultureInfo.InvariantCulture), out str)); }
internal static object DefaultToType(IConvertible value, Type targetType, IFormatProvider provider) { if (targetType == null) { throw new ArgumentNullException("targetType"); } RuntimeType left = targetType as RuntimeType; if (left != null) { if (value.GetType() == targetType) { return value; } if (left == Convert.ConvertTypes[3]) { return value.ToBoolean(provider); } if (left == Convert.ConvertTypes[4]) { return value.ToChar(provider); } if (left == Convert.ConvertTypes[5]) { return value.ToSByte(provider); } if (left == Convert.ConvertTypes[6]) { return value.ToByte(provider); } if (left == Convert.ConvertTypes[7]) { return value.ToInt16(provider); } if (left == Convert.ConvertTypes[8]) { return value.ToUInt16(provider); } if (left == Convert.ConvertTypes[9]) { return value.ToInt32(provider); } if (left == Convert.ConvertTypes[10]) { return value.ToUInt32(provider); } if (left == Convert.ConvertTypes[11]) { return value.ToInt64(provider); } if (left == Convert.ConvertTypes[12]) { return value.ToUInt64(provider); } if (left == Convert.ConvertTypes[13]) { return value.ToSingle(provider); } if (left == Convert.ConvertTypes[14]) { return value.ToDouble(provider); } if (left == Convert.ConvertTypes[15]) { return value.ToDecimal(provider); } if (left == Convert.ConvertTypes[16]) { return value.ToDateTime(provider); } if (left == Convert.ConvertTypes[18]) { return value.ToString(provider); } if (left == Convert.ConvertTypes[1]) { return value; } if (left == Convert.EnumType) { return (Enum)value; } if (left == Convert.ConvertTypes[2]) { throw new InvalidCastException(Environment.GetResourceString("InvalidCast_DBNull")); } if (left == Convert.ConvertTypes[0]) { throw new InvalidCastException(Environment.GetResourceString("InvalidCast_Empty")); } } throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", new object[] { value.GetType().FullName, targetType.FullName })); }
internal static Object DefaultToType(IConvertible value, Type targetType, IFormatProvider provider) { Contract.Requires(value != null, "[Convert.DefaultToType]value!=null"); if (targetType==null) { throw new ArgumentNullException("targetType"); } Contract.EndContractBlock(); RuntimeType rtTargetType = targetType as RuntimeType; if (rtTargetType != null) { if (value.GetType() == targetType) { return value; } if (rtTargetType == ConvertTypes[(int)TypeCode.Boolean]) return value.ToBoolean(provider); if (rtTargetType == ConvertTypes[(int)TypeCode.Char]) return value.ToChar(provider); if (rtTargetType == ConvertTypes[(int)TypeCode.SByte]) return value.ToSByte(provider); if (rtTargetType == ConvertTypes[(int)TypeCode.Byte]) return value.ToByte(provider); if (rtTargetType == ConvertTypes[(int)TypeCode.Int16]) return value.ToInt16(provider); if (rtTargetType == ConvertTypes[(int)TypeCode.UInt16]) return value.ToUInt16(provider); if (rtTargetType == ConvertTypes[(int)TypeCode.Int32]) return value.ToInt32(provider); if (rtTargetType == ConvertTypes[(int)TypeCode.UInt32]) return value.ToUInt32(provider); if (rtTargetType == ConvertTypes[(int)TypeCode.Int64]) return value.ToInt64(provider); if (rtTargetType == ConvertTypes[(int)TypeCode.UInt64]) return value.ToUInt64(provider); if (rtTargetType == ConvertTypes[(int)TypeCode.Single]) return value.ToSingle(provider); if (rtTargetType == ConvertTypes[(int)TypeCode.Double]) return value.ToDouble(provider); if (rtTargetType == ConvertTypes[(int)TypeCode.Decimal]) return value.ToDecimal(provider); if (rtTargetType == ConvertTypes[(int)TypeCode.DateTime]) return value.ToDateTime(provider); if (rtTargetType == ConvertTypes[(int)TypeCode.String]) return value.ToString(provider); if (rtTargetType == ConvertTypes[(int)TypeCode.Object]) return (Object)value; // Need to special case Enum because typecode will be underlying type, e.g. Int32 if (rtTargetType == EnumType) return (Enum)value; if (rtTargetType == ConvertTypes[(int)TypeCode.DBNull]) throw new InvalidCastException(Environment.GetResourceString("InvalidCast_DBNull")); if (rtTargetType == ConvertTypes[(int)TypeCode.Empty]) throw new InvalidCastException(Environment.GetResourceString("InvalidCast_Empty")); } throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", value.GetType().FullName, targetType.FullName)); }
internal static bool JScriptStrictEquals(object v1, object v2, IConvertible ic1, IConvertible ic2, TypeCode t1, TypeCode t2, bool checkForDebuggerObjects) { long num7; switch (t1) { case TypeCode.Empty: return (t2 == TypeCode.Empty); case TypeCode.Object: if (v1 != v2) { if ((v1 is Microsoft.JScript.Missing) || (v1 is System.Reflection.Missing)) { v1 = null; } if (v1 == v2) { return true; } if ((v2 is Microsoft.JScript.Missing) || (v2 is System.Reflection.Missing)) { v2 = null; } if (checkForDebuggerObjects) { IDebuggerObject obj2 = v1 as IDebuggerObject; if (obj2 != null) { IDebuggerObject o = v2 as IDebuggerObject; if (o != null) { return obj2.IsEqual(o); } } } return (v1 == v2); } return true; case TypeCode.DBNull: return (t2 == TypeCode.DBNull); case TypeCode.Boolean: if (t2 != TypeCode.Boolean) { return false; } return (ic1.ToBoolean(null) == ic2.ToBoolean(null)); case TypeCode.Char: { char ch = ic1.ToChar(null); switch (t2) { case TypeCode.Char: return (ch == ic2.ToChar(null)); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: return (ch == ic2.ToInt64(null)); case TypeCode.UInt64: return (ch == ic2.ToUInt64(null)); case TypeCode.Single: case TypeCode.Double: return (((double) ch) == ic2.ToDouble(null)); case TypeCode.Decimal: return (ch == ic2.ToDecimal(null)); case TypeCode.String: { string str = ic2.ToString(null); return ((str.Length == 1) && (ch == str[0])); } } break; } case TypeCode.SByte: { sbyte num = ic1.ToSByte(null); switch (t2) { case TypeCode.Char: return (num == ic2.ToChar(null)); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: return (num == ic2.ToInt64(null)); case TypeCode.UInt64: return ((num >= 0) && (num == ic2.ToUInt64(null))); case TypeCode.Single: return (num == ic2.ToSingle(null)); case TypeCode.Double: return (num == ic2.ToDouble(null)); case TypeCode.Decimal: return (num == ic2.ToDecimal(null)); } return false; } case TypeCode.Byte: { byte num2 = ic1.ToByte(null); switch (t2) { case TypeCode.Char: return (num2 == ic2.ToChar(null)); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: return (num2 == ic2.ToInt64(null)); case TypeCode.UInt64: return (num2 == ic2.ToUInt64(null)); case TypeCode.Single: return (num2 == ic2.ToSingle(null)); case TypeCode.Double: return (num2 == ic2.ToDouble(null)); case TypeCode.Decimal: return (num2 == ic2.ToDecimal(null)); } return false; } case TypeCode.Int16: { short num3 = ic1.ToInt16(null); switch (t2) { case TypeCode.Char: return (num3 == ic2.ToChar(null)); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: return (num3 == ic2.ToInt64(null)); case TypeCode.UInt64: return ((num3 >= 0) && (num3 == ic2.ToUInt64(null))); case TypeCode.Single: return (num3 == ic2.ToSingle(null)); case TypeCode.Double: return (num3 == ic2.ToDouble(null)); case TypeCode.Decimal: return (num3 == ic2.ToDecimal(null)); } return false; } case TypeCode.UInt16: { ushort num4 = ic1.ToUInt16(null); switch (t2) { case TypeCode.Char: return (num4 == ic2.ToChar(null)); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: return (num4 == ic2.ToInt64(null)); case TypeCode.UInt64: return (num4 == ic2.ToUInt64(null)); case TypeCode.Single: return (num4 == ic2.ToSingle(null)); case TypeCode.Double: return (num4 == ic2.ToDouble(null)); case TypeCode.Decimal: return (num4 == ic2.ToDecimal(null)); } return false; } case TypeCode.Int32: { int num5 = ic1.ToInt32(null); switch (t2) { case TypeCode.Char: return (num5 == ic2.ToChar(null)); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: return (num5 == ic2.ToInt64(null)); case TypeCode.UInt64: return ((num5 >= 0) && (num5 == ic2.ToUInt64(null))); case TypeCode.Single: return (num5 == ic2.ToSingle(null)); case TypeCode.Double: return (num5 == ic2.ToDouble(null)); case TypeCode.Decimal: return (num5 == ic2.ToDecimal(null)); } return false; } case TypeCode.UInt32: { uint num6 = ic1.ToUInt32(null); switch (t2) { case TypeCode.Char: return (num6 == ic2.ToChar(null)); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: return (num6 == ic2.ToInt64(null)); case TypeCode.UInt64: return (num6 == ic2.ToUInt64(null)); case TypeCode.Single: return (num6 == ic2.ToSingle(null)); case TypeCode.Double: return (num6 == ic2.ToDouble(null)); case TypeCode.Decimal: return (num6 == ic2.ToDecimal(null)); } return false; } case TypeCode.Int64: num7 = ic1.ToInt64(null); switch (t2) { case TypeCode.Char: return (num7 == ic2.ToChar(null)); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: return (num7 == ic2.ToInt64(null)); case TypeCode.UInt64: return ((num7 >= 0L) && (num7 == ic2.ToUInt64(null))); case TypeCode.Single: return (num7 == ic2.ToSingle(null)); case TypeCode.Double: return (num7 == ic2.ToDouble(null)); case TypeCode.Decimal: return (num7 == ic2.ToDecimal(null)); } return false; case TypeCode.UInt64: { ulong num8 = ic1.ToUInt64(null); switch (t2) { case TypeCode.Char: return (num8 == ic2.ToChar(null)); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: num7 = ic2.ToInt64(null); return ((num7 >= 0L) && (num8 == num7)); case TypeCode.UInt64: return (num8 == ic2.ToUInt64(null)); case TypeCode.Single: return (num8 == ic2.ToSingle(null)); case TypeCode.Double: return (num8 == ic2.ToDouble(null)); case TypeCode.Decimal: return (num8 == ic2.ToDecimal(null)); } return false; } case TypeCode.Single: { float num9 = ic1.ToSingle(null); switch (t2) { case TypeCode.Char: return (num9 == ((float) ic2.ToChar(null))); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: return (num9 == ic2.ToInt64(null)); case TypeCode.UInt64: return (num9 == ic2.ToUInt64(null)); case TypeCode.Single: return (num9 == ic2.ToSingle(null)); case TypeCode.Double: return (num9 == ic2.ToSingle(null)); case TypeCode.Decimal: return (((decimal) num9) == ic2.ToDecimal(null)); } return false; } case TypeCode.Double: { double num10 = ic1.ToDouble(null); switch (t2) { case TypeCode.Char: return (num10 == ((double) ic2.ToChar(null))); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: return (num10 == ic2.ToInt64(null)); case TypeCode.UInt64: return (num10 == ic2.ToUInt64(null)); case TypeCode.Single: return (((float) num10) == ic2.ToSingle(null)); case TypeCode.Double: return (num10 == ic2.ToDouble(null)); case TypeCode.Decimal: return (((decimal) num10) == ic2.ToDecimal(null)); } return false; } case TypeCode.Decimal: { decimal num11 = ic1.ToDecimal(null); switch (t2) { case TypeCode.Char: return (num11 == ic2.ToChar(null)); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: return (num11 == ic2.ToInt64(null)); case TypeCode.UInt64: return (num11 == ic2.ToUInt64(null)); case TypeCode.Single: return (num11 == ((decimal) ic2.ToSingle(null))); case TypeCode.Double: return (num11 == ((decimal) ic2.ToDouble(null))); case TypeCode.Decimal: return (num11 == ic2.ToDecimal(null)); } return false; } case TypeCode.DateTime: if (t2 != TypeCode.DateTime) { return false; } return (ic1.ToDateTime(null) == ic2.ToDateTime(null)); case TypeCode.String: { if (t2 != TypeCode.Char) { if (t2 != TypeCode.String) { return false; } if (v1 != v2) { return ic1.ToString(null).Equals(ic2.ToString(null)); } return true; } string str2 = ic1.ToString(null); if (str2.Length != 1) { return false; } return (str2[0] == ic2.ToChar(null)); } default: return false; } return false; }
// Default implementation of the "ToType" methods in // the primitive classes like Byte, Int32, Boolean, etc. internal static Object DefaultToType(IConvertible obj, Type targetType, IFormatProvider provider, bool recursive) { if(targetType != null) { if(obj.GetType() == targetType) { return obj; } else if(targetType == ConvertTypes[(int)TypeCode.Boolean]) { return (Object)(obj.ToBoolean(provider)); } else if(targetType == ConvertTypes[(int)TypeCode.Char]) { return (Object)(obj.ToChar(provider)); } else if(targetType == ConvertTypes[(int)TypeCode.SByte]) { return (Object)(obj.ToSByte(provider)); } else if(targetType == ConvertTypes[(int)TypeCode.Byte]) { return (Object)(obj.ToByte(provider)); } else if(targetType == ConvertTypes[(int)TypeCode.Int16]) { return (Object)(obj.ToInt16(provider)); } else if(targetType == ConvertTypes[(int)TypeCode.UInt16]) { return (Object)(obj.ToUInt16(provider)); } else if(targetType == ConvertTypes[(int)TypeCode.Int32]) { return (Object)(obj.ToInt32(provider)); } else if(targetType == ConvertTypes[(int)TypeCode.UInt32]) { return (Object)(obj.ToUInt32(provider)); } else if(targetType == ConvertTypes[(int)TypeCode.Int64]) { return (Object)(obj.ToInt64(provider)); } else if(targetType == ConvertTypes[(int)TypeCode.UInt64]) { return (Object)(obj.ToUInt64(provider)); } else if(targetType == ConvertTypes[(int)TypeCode.Single]) { return (Object)(obj.ToSingle(provider)); } else if(targetType == ConvertTypes[(int)TypeCode.Double]) { return (Object)(obj.ToDouble(provider)); } else if(targetType == ConvertTypes[(int)TypeCode.Decimal]) { return (Object)(obj.ToDecimal(provider)); } else if(targetType == ConvertTypes[(int)TypeCode.DateTime]) { return (Object)(obj.ToDateTime(provider)); } else if(targetType == ConvertTypes[(int)TypeCode.String]) { return (Object)(obj.ToString(provider)); } else if(targetType == ConvertTypes[(int)TypeCode.Object]) { return obj; } else if(targetType == ConvertTypes[(int)TypeCode.Empty]) { throw new InvalidCastException (_("InvalidCast_Empty")); } else if(targetType == ConvertTypes[(int)TypeCode.DBNull]) { throw new InvalidCastException (_("InvalidCast_DBNull")); } else if(recursive) { throw new InvalidCastException (String.Format (_("InvalidCast_FromTo"), obj.GetType().FullName, targetType.FullName)); } else { // We weren't called from a "ToType" method, // so we can use it to handle the default case. return obj.ToType(targetType, provider); } } else { throw new ArgumentNullException("targetType"); } }
public static Literal DoAddOvf(IConvertible ic1, IConvertible ic2, TypeCode code1, TypeCode code2, BinaryExpression binaryExpression){ TypeNode type = SystemTypes.Object; object val = null; checked{switch(code1){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: int i = ic1.ToInt32(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Byte: case TypeCode.Char: case TypeCode.UInt16: val = i + ic2.ToInt32(null); type = SystemTypes.Int32; break; case TypeCode.Int64: case TypeCode.UInt32: case TypeCode.UInt64: val = i + ic2.ToInt64(null); type = SystemTypes.Int64; break; case TypeCode.Single: val = i + ic2.ToSingle(null); type = SystemTypes.Single; break; case TypeCode.Double: val = i + ic2.ToDouble(null); type = SystemTypes.Double; break; case TypeCode.Decimal: val = i + ic2.ToDecimal(null); type = SystemTypes.Decimal; break; default: return null; } break; case TypeCode.Byte: case TypeCode.UInt16: ushort us = ic1.ToUInt16(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: val = us + ic2.ToInt32(null); type = SystemTypes.Int32; break; case TypeCode.Byte: case TypeCode.UInt16: case TypeCode.Char: case TypeCode.UInt32: val = us + ic2.ToUInt32(null); type = SystemTypes.UInt32; break; case TypeCode.Int64: val = us + ic2.ToInt64(null); type = SystemTypes.Int64; break; case TypeCode.UInt64: val = us + ic2.ToUInt64(null); type = SystemTypes.UInt64; break; case TypeCode.Single: val = us + ic2.ToSingle(null); type = SystemTypes.Single; break; case TypeCode.Double: val = us + ic2.ToDouble(null); type = SystemTypes.Double; break; case TypeCode.Decimal: val = us + ic2.ToDecimal(null); type = SystemTypes.Decimal; break; default: return null; } break; case TypeCode.UInt32: uint ui = ic1.ToUInt32(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: val = ui + ic2.ToInt64(null); type = SystemTypes.Int64; break; case TypeCode.Byte: case TypeCode.UInt16: case TypeCode.Char: case TypeCode.UInt32: val = ui + ic2.ToUInt32(null); type = SystemTypes.UInt32; break; case TypeCode.UInt64: val = ui + ic2.ToUInt64(null); type = SystemTypes.UInt64; break; case TypeCode.Single: val = ui + ic2.ToSingle(null); type = SystemTypes.Single; break; case TypeCode.Double: val = ui + ic2.ToDouble(null); type = SystemTypes.Double; break; case TypeCode.Decimal: val = ui + ic2.ToDecimal(null); type = SystemTypes.Decimal; break; default: return null; } break; case TypeCode.Int64: long l = ic1.ToInt64(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: val = l + ic2.ToInt64(null); type = SystemTypes.Int64; break; case TypeCode.Byte: case TypeCode.UInt16: case TypeCode.Char: case TypeCode.UInt32: val = l + ic2.ToUInt32(null); type = SystemTypes.UInt32; break; case TypeCode.UInt64: if (l >= 0){ val = ((ulong)l) + ic2.ToUInt64(null); type = SystemTypes.UInt64; }else{ val = l + (long)ic2.ToUInt64(null); type = SystemTypes.Int64; } break; case TypeCode.Single: val = l + ic2.ToSingle(null); type = SystemTypes.Single; break; case TypeCode.Double: val = l + ic2.ToDouble(null); type = SystemTypes.Double; break; case TypeCode.Decimal: val = l + ic2.ToDecimal(null); type = SystemTypes.Decimal; break; default: return null; } break; case TypeCode.UInt64: ulong ul = ic1.ToUInt64(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Byte: case TypeCode.UInt16: case TypeCode.Char: case TypeCode.UInt32: val = ul + ic2.ToUInt32(null); type = SystemTypes.UInt32; break; case TypeCode.Int64: case TypeCode.UInt64: val = ul + ic2.ToUInt64(null); type = SystemTypes.UInt64; break; case TypeCode.Single: val = ul + ic2.ToSingle(null); type = SystemTypes.Single; break; case TypeCode.Double: val = ul + ic2.ToDouble(null); type = SystemTypes.Double; break; case TypeCode.Decimal: val = ul + ic2.ToDecimal(null); type = SystemTypes.Decimal; break; default: return null; } break; case TypeCode.Single: float f = ic1.ToSingle(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: val = f + ic2.ToInt16(null); type = SystemTypes.Single; break; case TypeCode.Int32: case TypeCode.Int64: val = f + (double)ic2.ToInt64(null); type = SystemTypes.Double; break; case TypeCode.Byte: case TypeCode.Char: case TypeCode.UInt16: val = f + ic2.ToUInt16(null); type = SystemTypes.Single; break; case TypeCode.UInt32: case TypeCode.UInt64: val = f + (double)ic2.ToUInt64(null); type = SystemTypes.Double; break; case TypeCode.Single: case TypeCode.Double: val = f + ic2.ToDouble(null); type = SystemTypes.Double; break; case TypeCode.Decimal: val = f + (double)ic2.ToDecimal(null); type = SystemTypes.Double; break; default: return null; } break; case TypeCode.Double: double d = ic1.ToDouble(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: val = d + ic2.ToInt64(null); type = SystemTypes.Double; break; case TypeCode.Byte: case TypeCode.Char: case TypeCode.UInt16: case TypeCode.UInt32: case TypeCode.UInt64: val = d + ic2.ToUInt64(null); type = SystemTypes.Double; break; case TypeCode.Single: case TypeCode.Double: val = d + ic2.ToDouble(null); type = SystemTypes.Double; break; case TypeCode.Decimal: val = d + (double)ic2.ToDecimal(null); type = SystemTypes.Double; break; default: return null; } break; case TypeCode.Decimal: decimal dec = ic1.ToDecimal(null); switch(code2){ case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Char: case TypeCode.Int32: val = dec + ic2.ToInt32(null); type = SystemTypes.Decimal; break; case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: val = dec + ic2.ToInt64(null); type = SystemTypes.Decimal; break; case TypeCode.Decimal: val = dec + ic2.ToDecimal(null); type = SystemTypes.Decimal; break; default: return null; } break; case TypeCode.String: string str = ic1.ToString(null); switch (code2) { case TypeCode.String: val = str + ic2.ToString(null); type = SystemTypes.String; break; default: return null; } break; default: return null; }} return new Literal(val, type, binaryExpression.SourceContext); }
public static Literal DoRightShift(IConvertible ic1, IConvertible ic2, TypeCode code1, TypeCode code2, BinaryExpression binaryExpression){ TypeNode type = SystemTypes.Object; object val = null; int shift = 0; switch (code2){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Byte: case TypeCode.UInt16: shift = ic2.ToInt32(null) & 0x3f; break; case TypeCode.Int64: shift = ((int)ic2.ToInt64(null)) & 0x3f; break; case TypeCode.UInt32: case TypeCode.UInt64: shift = ((int)ic2.ToUInt64(null)) & 0x3f; break; default: return null; } switch(code1){ case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Char: case TypeCode.Int32: int i = ic1.ToInt32(null); val = i >> shift; type = SystemTypes.Int32; break; case TypeCode.UInt32: uint ui = ic1.ToUInt32(null); val = ui >> shift; type = SystemTypes.UInt32; break; case TypeCode.Int64: long l = ic1.ToInt64(null); val = l >> shift; type = SystemTypes.Int64; break; case TypeCode.UInt64: ulong ul = ic1.ToUInt64(null); val = ul >> shift; type = SystemTypes.UInt64; break; default: return null; } return new Literal(val, type, binaryExpression.SourceContext); }
public static Literal DoLe(IConvertible ic1, IConvertible ic2, TypeCode code1, TypeCode code2, BinaryExpression binaryExpression){ TypeNode type = SystemTypes.Boolean; object val = null; switch(code1){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: int i = ic1.ToInt32(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Byte: case TypeCode.Char: case TypeCode.UInt16: val = i <= ic2.ToInt32(null); break; case TypeCode.Int64: case TypeCode.UInt32: val = ((long)i) <= ic2.ToInt64(null); break; case TypeCode.UInt64: val = ((ulong)i) <= ic2.ToUInt64(null); break; case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: return null; default: return null; } break; case TypeCode.Byte: case TypeCode.UInt16: ushort us = ic1.ToUInt16(null); switch(code2){ case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Char: case TypeCode.Int32: val = ((int)us) <= ic2.ToInt32(null); break; case TypeCode.UInt32: val = ((uint)us) <= ic2.ToUInt32(null); break; case TypeCode.Int64: val = ((long)us) <= ic2.ToInt64(null); break; case TypeCode.UInt64: val = ((ulong)us) <= ic2.ToUInt64(null); break; case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: return null; default: return null; } break; case TypeCode.UInt32: uint ui = ic1.ToUInt32(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: val = ((long)ui) <= ic2.ToInt64(null); break; case TypeCode.Byte: case TypeCode.UInt16: case TypeCode.Char: case TypeCode.UInt32: val = ui <= ic2.ToUInt32(null); break; case TypeCode.UInt64: val = ((ulong)ui) <= ic2.ToUInt64(null); break; case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: return null; default: return null; } break; case TypeCode.Int64: long l = ic1.ToInt64(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: case TypeCode.Byte: case TypeCode.UInt16: case TypeCode.Char: case TypeCode.UInt32: val = l <= ic2.ToInt64(null); break; case TypeCode.UInt64: val = ((ulong)l) <= ic2.ToUInt64(null); break; case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: return null; default: return null; } break; case TypeCode.UInt64: ulong ul = ic1.ToUInt64(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Byte: case TypeCode.UInt16: case TypeCode.Char: case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: val = ul <= ic2.ToUInt64(null); break; case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: return null; default: return null; } break; case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: return null; default: return null; } return new Literal(val, type, binaryExpression.SourceContext); }
private static object InternalNegObj(object obj, IConvertible conv, TypeCode tc) { switch (tc) { case TypeCode.Empty: return 0; case TypeCode.Boolean: if (obj is bool) { return -((short) -(((bool) obj) > false)); } return -((short) -(conv.ToBoolean(null) > false)); case TypeCode.Byte: if (obj is byte) { return (short) -((byte) obj); } return (short) -conv.ToByte(null); case TypeCode.Int16: int num4; if (obj is short) { num4 = 0 - ((short) obj); } else { num4 = 0 - conv.ToInt16(null); } if ((num4 >= -32768) && (num4 <= 0x7fff)) { return (short) num4; } return num4; case TypeCode.Int32: long num5; if (obj is int) { num5 = 0L - ((int) obj); } else { num5 = 0L - conv.ToInt32(null); } if ((num5 >= -2147483648L) && (num5 <= 0x7fffffffL)) { return (int) num5; } return num5; case TypeCode.Int64: try { if (obj is long) { return (0L - ((long) obj)); } return (0L - conv.ToInt64(null)); } catch (StackOverflowException exception) { throw exception; } catch (OutOfMemoryException exception2) { throw exception2; } catch (ThreadAbortException exception3) { throw exception3; } catch (Exception) { return decimal.Negate(conv.ToDecimal(null)); } break; case TypeCode.Single: goto Label_01B9; case TypeCode.Double: if (obj is double) { return -((double) obj); } return -conv.ToDouble(null); case TypeCode.Decimal: break; case TypeCode.String: { string str = obj as string; if (str == null) { return -DoubleType.FromString(conv.ToString(null)); } return -DoubleType.FromString(str); } default: throw GetNoValidOperatorException(obj); } try { if (obj is decimal) { return decimal.Negate((decimal) obj); } return decimal.Negate(conv.ToDecimal(null)); } catch (StackOverflowException exception4) { throw exception4; } catch (OutOfMemoryException exception5) { throw exception5; } catch (ThreadAbortException exception6) { throw exception6; } catch (Exception) { return -conv.ToDouble(null); } Label_01B9: if (obj is float) { return -((float) obj); } return -conv.ToSingle(null); }
internal static Object DefaultToType(IConvertible value, Type targetType, IFormatProvider provider) { Contract.Requires(value != null, "[Convert.DefaultToType]value!=null"); if (targetType == null) { throw new ArgumentNullException("targetType"); } Contract.EndContractBlock(); if (value.GetType() == targetType) return value; if (targetType == CommonRuntimeTypes.Boolean) return value.ToBoolean(provider); if (targetType == CommonRuntimeTypes.Char) return value.ToChar(provider); if (targetType == CommonRuntimeTypes.SByte) return value.ToSByte(provider); if (targetType == CommonRuntimeTypes.Byte) return value.ToByte(provider); if (targetType == CommonRuntimeTypes.Int16) return value.ToInt16(provider); if (targetType == CommonRuntimeTypes.UInt16) return value.ToUInt16(provider); if (targetType == CommonRuntimeTypes.Int32) return value.ToInt32(provider); if (targetType == CommonRuntimeTypes.UInt32) return value.ToUInt32(provider); if (targetType == CommonRuntimeTypes.Int64) return value.ToInt64(provider); if (targetType == CommonRuntimeTypes.UInt64) return value.ToUInt64(provider); if (targetType == CommonRuntimeTypes.Single) return value.ToSingle(provider); if (targetType == CommonRuntimeTypes.Double) return value.ToDouble(provider); if (targetType == CommonRuntimeTypes.Decimal) return value.ToDecimal(provider); if (targetType == CommonRuntimeTypes.DateTime) return value.ToDateTime(provider); if (targetType == CommonRuntimeTypes.String) return value.ToString(provider); if (targetType == CommonRuntimeTypes.Object) return (Object)value; if (targetType == CommonRuntimeTypes.Enum) return (Enum)value; throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, value.GetType().ToString(), targetType.Name)); }
public static Literal DoOr(IConvertible ic1, IConvertible ic2, TypeCode code1, TypeCode code2, BinaryExpression binaryExpression){ TypeNode type = SystemTypes.Object; object val = null; switch(code1){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: int i = ic1.ToInt32(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Byte: case TypeCode.Char: case TypeCode.UInt16: val = i | ic2.ToInt32(null); type = SystemTypes.Int32; break; case TypeCode.UInt32: if (i >= 0){ val = ((uint)i) | ic2.ToUInt32(null); type = SystemTypes.UInt32; break; } goto case TypeCode.Int64; case TypeCode.Int64: long lng = i; val = lng | ic2.ToInt64(null); type = SystemTypes.Int64; break; case TypeCode.UInt64: ulong ulng = (ulong) i; val = ulng | ic2.ToUInt64(null); type = SystemTypes.UInt64; break; case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: return null; default: return null; } break; case TypeCode.Byte: case TypeCode.Char: case TypeCode.UInt16: ushort us = ic1.ToUInt16(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Byte: case TypeCode.UInt16: case TypeCode.Char: val = ((int)us) | ic2.ToInt32(null); type = SystemTypes.Int32; break; case TypeCode.UInt32: val = ((uint)us) | ic2.ToUInt32(null); type = SystemTypes.UInt32; break; case TypeCode.Int64: val = ((long)us) | ic2.ToInt64(null); type = SystemTypes.Int64; break; case TypeCode.UInt64: val = ((ulong)us) | ic2.ToUInt64(null); type = SystemTypes.UInt64; break; case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: return null; default: return null; } break; case TypeCode.UInt32: uint ui = ic1.ToUInt32(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: i = ic2.ToInt32(null); if (i >= 0){ val = ui | (uint)i; type = SystemTypes.UInt32; break; } goto case TypeCode.Int64; case TypeCode.Int64: val = ((long)ui) | ic2.ToInt64(null); type = SystemTypes.Int64; break; case TypeCode.Byte: case TypeCode.UInt16: case TypeCode.Char: case TypeCode.UInt32: val = ui | ic2.ToUInt32(null); type = SystemTypes.UInt32; break; case TypeCode.UInt64: val = ((ulong)ui) | ic2.ToUInt64(null); type = SystemTypes.UInt64; break; case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: return null; default: return null; } break; case TypeCode.Int64: long l = ic1.ToInt64(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: case TypeCode.Byte: case TypeCode.UInt16: case TypeCode.Char: case TypeCode.UInt32: val = l | ic2.ToInt64(null); type = SystemTypes.Int64; break; case TypeCode.UInt64: val = ((ulong)l) | ic2.ToUInt64(null); type = SystemTypes.UInt64; break; case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: return null; default: return null; } break; case TypeCode.UInt64: ulong ul = ic1.ToUInt64(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Byte: case TypeCode.UInt16: case TypeCode.Char: case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: val = ul | ic2.ToUInt64(null); type = SystemTypes.UInt64; break; case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: return null; default: return null; } break; case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: return null; default: return null; } return new Literal(val, type, binaryExpression.SourceContext); }
public IConvertible Random(IConvertible min, IConvertible max) { return _Random(min.ToInt32(null), max.ToInt32(null)); }
public static Literal DoSubOvf(IConvertible ic1, IConvertible ic2, TypeCode code1, TypeCode code2, BinaryExpression binaryExpression){ TypeNode type = SystemTypes.Object; object val = null; checked{switch(code1){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: int i = ic1.ToInt32(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Byte: case TypeCode.Char: case TypeCode.UInt16: val = i - ic2.ToInt32(null); type = SystemTypes.Int32; break; case TypeCode.Int64: case TypeCode.UInt32: case TypeCode.UInt64: val = i - ic2.ToInt64(null); type = SystemTypes.Int64; break; case TypeCode.Single: val = i - ic2.ToSingle(null); type = SystemTypes.Single; break; case TypeCode.Double: val = i - ic2.ToDouble(null); type = SystemTypes.Double; break; case TypeCode.Decimal: val = i - ic2.ToDecimal(null); type = SystemTypes.Decimal; break; default: return null; } break; case TypeCode.Byte: case TypeCode.UInt16: ushort us = ic1.ToUInt16(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: val = us - ic2.ToInt32(null); type = SystemTypes.Int32; break; case TypeCode.Byte: case TypeCode.UInt16: case TypeCode.Char: case TypeCode.UInt32: val = us - ic2.ToUInt32(null); type = SystemTypes.UInt32; break; case TypeCode.Int64: val = us - ic2.ToInt64(null); type = SystemTypes.Int64; break; case TypeCode.UInt64: val = us - ic2.ToUInt64(null); type = SystemTypes.UInt64; break; case TypeCode.Single: case TypeCode.Double: val = us - ic2.ToDouble(null); type = SystemTypes.Double; break; case TypeCode.Decimal: val = us - ic2.ToDecimal(null); type = SystemTypes.Decimal; break; default: return null; } break; case TypeCode.Char: char ch = ic1.ToChar(null); if (code2 != TypeCode.Char) goto default; val = ch - ic2.ToChar(null); type = SystemTypes.Int32; break; case TypeCode.UInt32: uint ui = ic1.ToUInt32(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: val = ui - ic2.ToInt64(null); type = SystemTypes.Int64; break; case TypeCode.Byte: case TypeCode.UInt16: case TypeCode.Char: case TypeCode.UInt32: val = ui - ic2.ToUInt32(null); type = SystemTypes.UInt32; break; case TypeCode.UInt64: val = ui - ic2.ToUInt64(null); type = SystemTypes.UInt64; break; case TypeCode.Single: val = ui - ic2.ToSingle(null); type = SystemTypes.Single; break; case TypeCode.Double: val = ui - ic2.ToDouble(null); type = SystemTypes.Double; break; case TypeCode.Decimal: val = ui - ic2.ToDecimal(null); type = SystemTypes.Decimal; break; default: return null; } break; case TypeCode.Int64: long l = ic1.ToInt64(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: val = l - ic2.ToInt64(null); type = SystemTypes.Int64; break; case TypeCode.Byte: case TypeCode.UInt16: case TypeCode.Char: case TypeCode.UInt32: val = l - ic2.ToUInt32(null); type = SystemTypes.UInt32; break; case TypeCode.UInt64: val = l - (long)ic2.ToUInt64(null); type = SystemTypes.UInt64; break; case TypeCode.Single: val = l - ic2.ToSingle(null); type = SystemTypes.Single; break; case TypeCode.Double: val = l - ic2.ToDouble(null); type = SystemTypes.Double; break; case TypeCode.Decimal: val = l - ic2.ToDecimal(null); type = SystemTypes.Decimal; break; default: return null; } break; case TypeCode.UInt64: ulong ul = ic1.ToUInt64(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Byte: case TypeCode.UInt16: case TypeCode.Char: case TypeCode.UInt32: val = ul - ic2.ToUInt32(null); type = SystemTypes.UInt64; break; case TypeCode.Int64: case TypeCode.UInt64: val = ul - ic2.ToUInt64(null); type = SystemTypes.UInt64; break; case TypeCode.Single: val = ul - ic2.ToSingle(null); type = SystemTypes.Single; break; case TypeCode.Double: val = ul - ic2.ToDouble(null); type = SystemTypes.Double; break; case TypeCode.Decimal: val = ul - ic2.ToDecimal(null); type = SystemTypes.Decimal; break; default: return null; } break; case TypeCode.Single: float f = ic1.ToSingle(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: val = f - ic2.ToInt16(null); type = SystemTypes.Single; break; case TypeCode.Int32: case TypeCode.Int64: val = f - (double)ic2.ToInt64(null); type = SystemTypes.Double; break; case TypeCode.Byte: case TypeCode.Char: case TypeCode.UInt16: val = f - ic2.ToUInt16(null); type = SystemTypes.Single; break; case TypeCode.UInt32: case TypeCode.UInt64: val = f - (double)ic2.ToUInt64(null); type = SystemTypes.Double; break; case TypeCode.Single: case TypeCode.Double: val = f - ic2.ToDouble(null); type = SystemTypes.Double; break; case TypeCode.Decimal: val = f - (double)ic2.ToDecimal(null); type = SystemTypes.Double; break; default: return null; } break; case TypeCode.Double: double d = ic1.ToDouble(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: val = d - ic2.ToInt64(null); type = SystemTypes.Double; break; case TypeCode.Byte: case TypeCode.Char: case TypeCode.UInt16: case TypeCode.UInt32: case TypeCode.UInt64: val = d - ic2.ToUInt64(null); type = SystemTypes.Double; break; case TypeCode.Single: case TypeCode.Double: val = d - ic2.ToDouble(null); type = SystemTypes.Double; break; case TypeCode.Decimal: val = d - (double)ic2.ToDecimal(null); type = SystemTypes.Double; break; default: return null; } break; case TypeCode.Decimal: decimal dec = ic1.ToDecimal(null); switch(code2){ case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Char: case TypeCode.Int32: val = dec - ic2.ToInt32(null); type = SystemTypes.Decimal; break; case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: val = dec - ic2.ToInt64(null); type = SystemTypes.Decimal; break; case TypeCode.Decimal: val = dec - ic2.ToDecimal(null); type = SystemTypes.Decimal; break; default: return null; } break; default: return null; } } return new Literal(val, type, binaryExpression.SourceContext); }
void EmitValue(IConvertible val) { switch (val.GetTypeCode()) { case TypeCode.UInt64: g.EmitI8Helper(unchecked((long)val.ToUInt64(null)), false); break; case TypeCode.Int64: g.EmitI8Helper(val.ToInt64(null), true); break; case TypeCode.UInt32: g.EmitI4Helper(unchecked((int)val.ToUInt64(null))); break; default: g.EmitI4Helper(val.ToInt32(null)); break; } }
public static Literal DoDiv(IConvertible ic1, IConvertible ic2, TypeCode code1, TypeCode code2, BinaryExpression binaryExpression){ TypeNode type = SystemTypes.Object; object val = null; switch(code1){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: int i = ic1.ToInt32(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Byte: case TypeCode.Char: case TypeCode.UInt16: val = i / ic2.ToInt32(null); type = SystemTypes.Int32; break; case TypeCode.Int64: case TypeCode.UInt32: case TypeCode.UInt64: val = i / ic2.ToInt64(null); type = SystemTypes.Int64; break; case TypeCode.Single: val = i / ic2.ToSingle(null); type = SystemTypes.Single; break; case TypeCode.Double: val = i / ic2.ToDouble(null); type = SystemTypes.Double; break; case TypeCode.Decimal: val = i / ic2.ToDecimal(null); type = SystemTypes.Decimal; break; default: return null; } break; case TypeCode.Byte: case TypeCode.UInt16: ushort us = ic1.ToUInt16(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: val = us / ic2.ToInt32(null); type = SystemTypes.Int32; break; case TypeCode.Byte: case TypeCode.UInt16: case TypeCode.Char: case TypeCode.UInt32: val = us / ic2.ToUInt32(null); type = SystemTypes.UInt32; break; case TypeCode.Int64: val = us / ic2.ToInt64(null); type = SystemTypes.Int64; break; case TypeCode.UInt64: val = us / ic2.ToUInt64(null); type = SystemTypes.UInt64; break; case TypeCode.Single: case TypeCode.Double: val = us / ic2.ToDouble(null); type = SystemTypes.Double; break; case TypeCode.Decimal: val = us / ic2.ToDecimal(null); type = SystemTypes.Decimal; break; default: return null; } break; case TypeCode.UInt32: uint ui = ic1.ToUInt32(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: val = ui / ic2.ToInt64(null); type = SystemTypes.Int64; break; case TypeCode.Byte: case TypeCode.UInt16: case TypeCode.Char: case TypeCode.UInt32: val = ui / ic2.ToUInt32(null); type = SystemTypes.UInt32; break; case TypeCode.UInt64: val = ui / ic2.ToUInt64(null); type = SystemTypes.UInt64; break; case TypeCode.Single: val = ui / ic2.ToSingle(null); type = SystemTypes.Single; break; case TypeCode.Double: val = ui / ic2.ToDouble(null); type = SystemTypes.Double; break; case TypeCode.Decimal: val = ui / ic2.ToDecimal(null); type = SystemTypes.Decimal; break; default: return null; } break; case TypeCode.Int64: long l = ic1.ToInt64(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: val = l / ic2.ToInt64(null); type = SystemTypes.Int64; break; case TypeCode.Byte: case TypeCode.UInt16: case TypeCode.Char: case TypeCode.UInt32: val = l / ic2.ToUInt32(null); type = SystemTypes.UInt32; break; case TypeCode.UInt64: val = l / (long)ic2.ToUInt64(null); type = SystemTypes.UInt64; break; case TypeCode.Single: val = l / ic2.ToSingle(null); type = SystemTypes.Single; break; case TypeCode.Double: val = l / ic2.ToDouble(null); type = SystemTypes.Double; break; case TypeCode.Decimal: val = l / ic2.ToDecimal(null); type = SystemTypes.Decimal; break; default: return null; } break; case TypeCode.UInt64: ulong ul = ic1.ToUInt64(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Byte: case TypeCode.UInt16: case TypeCode.Char: case TypeCode.UInt32: val = ul / ic2.ToUInt32(null); type = SystemTypes.UInt32; break; case TypeCode.Int64: case TypeCode.UInt64: val = ul / ic2.ToUInt64(null); type = SystemTypes.UInt64; break; case TypeCode.Single: val = ul / ic2.ToSingle(null); type = SystemTypes.Single; break; case TypeCode.Double: val = ul / ic2.ToDouble(null); type = SystemTypes.Double; break; case TypeCode.Decimal: val = ul / ic2.ToDecimal(null); type = SystemTypes.Decimal; break; default: return null; } break; case TypeCode.Single: float f = ic1.ToSingle(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: val = f / ic2.ToInt16(null); type = SystemTypes.Single; break; case TypeCode.Int32: case TypeCode.Int64: val = f / (double)ic2.ToInt64(null); type = SystemTypes.Double; break; case TypeCode.Byte: case TypeCode.Char: case TypeCode.UInt16: val = f / ic2.ToUInt16(null); type = SystemTypes.Single; break; case TypeCode.UInt32: case TypeCode.UInt64: val = f / (double)ic2.ToUInt64(null); type = SystemTypes.Double; break; case TypeCode.Single: val = f / ic2.ToSingle(null); type = SystemTypes.Single; break; case TypeCode.Double: val = f / ic2.ToDouble(null); type = SystemTypes.Double; break; case TypeCode.Decimal: val = f / (double)ic2.ToDecimal(null); type = SystemTypes.Double; break; default: return null; } break; case TypeCode.Double: double d = ic1.ToDouble(null); switch(code2){ case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: val = d / ic2.ToInt64(null); type = SystemTypes.Double; break; case TypeCode.Byte: case TypeCode.Char: case TypeCode.UInt16: case TypeCode.UInt32: case TypeCode.UInt64: val = d / ic2.ToUInt64(null); type = SystemTypes.Double; break; case TypeCode.Single: case TypeCode.Double: val = d / ic2.ToDouble(null); type = SystemTypes.Double; break; case TypeCode.Decimal: val = d / (double)ic2.ToDecimal(null); type = SystemTypes.Double; break; default: return null; } break; case TypeCode.Decimal: decimal dec = ic1.ToDecimal(null); switch(code2){ case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Char: case TypeCode.Int32: val = dec / ic2.ToInt32(null); type = SystemTypes.Decimal; break; case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: val = dec / ic2.ToInt64(null); type = SystemTypes.Decimal; break; case TypeCode.Decimal: val = dec / ic2.ToDecimal(null); type = SystemTypes.Decimal; break; default: return null; } break; default: return null; } return new Literal(val, type, binaryExpression.SourceContext); }
internal static bool JScriptStrictEquals(Object v1, Object v2, IConvertible ic1, IConvertible ic2, TypeCode t1, TypeCode t2, bool checkForDebuggerObjects){ switch (t1){ case TypeCode.Empty: return t2 == TypeCode.Empty; case TypeCode.Object: if (v1 == v2) return true; if (v1 is Missing || v1 is System.Reflection.Missing) v1 = null; if (v1 == v2) return true; if (v2 is Missing || v2 is System.Reflection.Missing) v2 = null; return v1 == v2; case TypeCode.DBNull: return t2 == TypeCode.DBNull; case TypeCode.Boolean: return t2 == TypeCode.Boolean && ic1.ToBoolean(null) == ic2.ToBoolean(null); case TypeCode.Char: Char ch = ic1.ToChar(null); switch(t2){ case TypeCode.Char: return ch == ic2.ToChar(null); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: return ch == ic2.ToInt64(null); case TypeCode.UInt64: return ch == ic2.ToUInt64(null); case TypeCode.Single: case TypeCode.Double: return ch == ic2.ToDouble(null); case TypeCode.Decimal: return ((Decimal)(int)ch) == ic2.ToDecimal(null); case TypeCode.String: String str = ic2.ToString(null); return str.Length == 1 && ch == str[0]; } return false; case TypeCode.SByte: SByte sb1 = ic1.ToSByte(null); switch (t2){ case TypeCode.Char: return sb1 == ic2.ToChar(null); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: return sb1 == ic2.ToInt64(null); case TypeCode.UInt64: return sb1 >= 0 && ((UInt64)sb1) == ic2.ToUInt64(null); case TypeCode.Single: return sb1 == ic2.ToSingle(null); case TypeCode.Double: return sb1 == ic2.ToDouble(null); case TypeCode.Decimal: return ((Decimal)sb1) == ic2.ToDecimal(null); } return false; case TypeCode.Byte: Byte b1 = ic1.ToByte(null); switch (t2){ case TypeCode.Char: return b1 == ic2.ToChar(null); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: return b1 == ic2.ToInt64(null); case TypeCode.UInt64: return b1 == ic2.ToUInt64(null); case TypeCode.Single: return b1 == ic2.ToSingle(null); case TypeCode.Double: return b1 == ic2.ToDouble(null); case TypeCode.Decimal: return ((Decimal)b1) == ic2.ToDecimal(null); } return false; case TypeCode.Int16: Int16 s1 = ic1.ToInt16(null); switch (t2){ case TypeCode.Char: return s1 == ic2.ToChar(null); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: return s1 == ic2.ToInt64(null); case TypeCode.UInt64: return s1 >= 0 && ((UInt64)s1) == ic2.ToUInt64(null); case TypeCode.Single: return s1 == ic2.ToSingle(null); case TypeCode.Double: return s1 == ic2.ToDouble(null); case TypeCode.Decimal: return ((Decimal)s1) == ic2.ToDecimal(null); } return false; case TypeCode.UInt16: UInt16 us1 = ic1.ToUInt16(null); switch (t2){ case TypeCode.Char: return us1 == ic2.ToChar(null); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: return us1 == ic2.ToInt64(null); case TypeCode.UInt64: return us1 == ic2.ToUInt64(null); case TypeCode.Single: return us1 == ic2.ToSingle(null); case TypeCode.Double: return us1 == ic2.ToDouble(null); case TypeCode.Decimal: return ((Decimal)us1) == ic2.ToDecimal(null); } return false; case TypeCode.Int32: Int32 i1 = ic1.ToInt32(null); switch (t2){ case TypeCode.Char: return i1 == ic2.ToChar(null); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: return i1 == ic2.ToInt64(null); case TypeCode.UInt64: return i1 >= 0 && ((UInt64)i1) == ic2.ToUInt64(null); case TypeCode.Single: return i1 == ic2.ToSingle(null); case TypeCode.Double: return i1 == ic2.ToDouble(null); case TypeCode.Decimal: return ((Decimal)i1) == ic2.ToDecimal(null); } return false; case TypeCode.UInt32: UInt32 ui1 = ic1.ToUInt32(null); switch (t2){ case TypeCode.Char: return ui1 == ic2.ToChar(null); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: return ui1 == ic2.ToInt64(null); case TypeCode.UInt64: return ui1 == ic2.ToUInt64(null); case TypeCode.Single: return ui1 == ic2.ToSingle(null); case TypeCode.Double: return ui1 == ic2.ToDouble(null); case TypeCode.Decimal: return ((Decimal)ui1) == ic2.ToDecimal(null); } return false; case TypeCode.Int64: Int64 l1 = ic1.ToInt64(null); switch (t2){ case TypeCode.Char: return l1 == ic2.ToChar(null); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: return l1 == ic2.ToInt64(null); case TypeCode.UInt64: return l1 >= 0 && ((UInt64)l1) == ic2.ToUInt64(null); case TypeCode.Single: return l1 == ic2.ToSingle(null); case TypeCode.Double: return l1 == ic2.ToDouble(null); case TypeCode.Decimal: return ((Decimal)l1) == ic2.ToDecimal(null); } return false; case TypeCode.UInt64: UInt64 ul1 = ic1.ToUInt64(null); switch (t2){ case TypeCode.Char: return ul1 == ic2.ToChar(null); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: l1 = ic2.ToInt64(null); return l1 >= 0 && ul1 == (UInt64)l1; case TypeCode.UInt64: return ul1 == ic2.ToUInt64(null); case TypeCode.Single: return ul1 == ic2.ToSingle(null); case TypeCode.Double: return ul1 == ic2.ToDouble(null); case TypeCode.Decimal: return ((Decimal)ul1) == ic2.ToDecimal(null); } return false; case TypeCode.Single: Single f1 = ic1.ToSingle(null); switch (t2){ case TypeCode.Char: return f1 == ic2.ToChar(null); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: return f1 == ic2.ToInt64(null); case TypeCode.UInt64: return f1 == ic2.ToUInt64(null); case TypeCode.Single: return f1 == ic2.ToSingle(null); case TypeCode.Double: return f1 == ic2.ToSingle(null); case TypeCode.Decimal: return ((Decimal)f1) == ic2.ToDecimal(null); } return false; case TypeCode.Double: Double d1 = ic1.ToDouble(null); switch (t2){ case TypeCode.Char: return d1 == ic2.ToChar(null); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: return d1 == ic2.ToInt64(null); case TypeCode.UInt64: return d1 == ic2.ToUInt64(null); case TypeCode.Single: return ((float)d1) == ic2.ToSingle(null); case TypeCode.Double: return d1 == ic2.ToDouble(null); case TypeCode.Decimal: return ((Decimal)d1) == ic2.ToDecimal(null); } return false; case TypeCode.Decimal: Decimal de1 = ic1.ToDecimal(null); switch (t2){ case TypeCode.Char: return de1 == (Decimal)(int)ic2.ToChar(null); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: return de1 == ic2.ToInt64(null); case TypeCode.UInt64: return de1 == ic2.ToUInt64(null); case TypeCode.Single: return de1 == (Decimal)ic2.ToSingle(null); case TypeCode.Double: return de1 == (Decimal)ic2.ToDouble(null); case TypeCode.Decimal: return de1 == ic2.ToDecimal(null); } return false; case TypeCode.DateTime: return t2 == TypeCode.DateTime && ic1.ToDateTime(null) == ic2.ToDateTime(null); case TypeCode.String: if (t2 == TypeCode.Char){ String str = ic1.ToString(null); return str.Length == 1 && str[0] == ic2.ToChar(null); } return t2 == TypeCode.String && (v1 == v2 || ic1.ToString(null).Equals(ic2.ToString(null))); } return false; //should never get here }
internal static double ToNumber(Object value, IConvertible ic){ switch (Convert.GetTypeCode(value, ic)){ case TypeCode.Empty: return Double.NaN; case TypeCode.DBNull: return 0; case TypeCode.Boolean: return ic.ToBoolean(null) ? 1 : 0; case TypeCode.Char: return (double)ic.ToChar(null); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: return (double)ic.ToInt32(null); case TypeCode.UInt32: case TypeCode.Int64: return (double)ic.ToInt64(null); case TypeCode.UInt64: return (double)ic.ToUInt64(null); case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: return ic.ToDouble(null); case TypeCode.Object: case TypeCode.DateTime: Object pval = Convert.ToPrimitive(value, PreferredType.Number, ref ic); if (pval != value) return Convert.ToNumber(pval, ic); else return Double.NaN; case TypeCode.String: return Convert.ToNumber(ic.ToString(null)); } return 0; //should never get here }
internal static Object DefaultToType(IConvertible value, Type targetType, IFormatProvider provider) { BCLDebug.Assert(value!=null, "[Convert.DefaultToType]value!=null"); if (targetType==null) { throw new ArgumentNullException("targetType"); } if (value.GetType()==targetType) { return value; } if (targetType==ConvertTypes[(int)TypeCode.Boolean]) return value.ToBoolean(provider); if (targetType==ConvertTypes[(int)TypeCode.Char]) return value.ToChar(provider); if (targetType==ConvertTypes[(int)TypeCode.SByte]) return value.ToSByte(provider); if (targetType==ConvertTypes[(int)TypeCode.Byte]) return value.ToByte(provider); if (targetType==ConvertTypes[(int)TypeCode.Int16]) return value.ToInt16(provider); if (targetType==ConvertTypes[(int)TypeCode.UInt16]) return value.ToUInt16(provider); if (targetType==ConvertTypes[(int)TypeCode.Int32]) return value.ToInt32(provider); if (targetType==ConvertTypes[(int)TypeCode.UInt32]) return value.ToUInt32(provider); if (targetType==ConvertTypes[(int)TypeCode.Int64]) return value.ToInt64(provider); if (targetType==ConvertTypes[(int)TypeCode.UInt64]) return value.ToUInt64(provider); if (targetType==ConvertTypes[(int)TypeCode.Single]) return value.ToSingle(provider); if (targetType==ConvertTypes[(int)TypeCode.Double]) return value.ToDouble(provider); if (targetType==ConvertTypes[(int)TypeCode.Decimal]) return value.ToDecimal(provider); if (targetType==ConvertTypes[(int)TypeCode.DateTime]) return value.ToDateTime(provider); if (targetType==ConvertTypes[(int)TypeCode.String]) { return value.ToString(provider); } if (targetType==ConvertTypes[(int)TypeCode.Object]) return (Object)value; if (targetType==ConvertTypes[(int)TypeCode.DBNull]) throw new InvalidCastException(Environment.GetResourceString("InvalidCast_DBNull")); if (targetType==ConvertTypes[(int)TypeCode.Empty]) throw new InvalidCastException(Environment.GetResourceString("InvalidCast_Empty")); throw new InvalidCastException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("InvalidCast_FromTo"), value.GetType().FullName, targetType.FullName)); }
internal static bool ToBoolean(Object value, IConvertible ic){ switch (Convert.GetTypeCode(value, ic)){ case TypeCode.Empty: return false; case TypeCode.Object: if (value is Missing || value is System.Reflection.Missing) return false; Type t = value.GetType(); MethodInfo meth = t.GetMethod("op_True", BindingFlags.ExactBinding|BindingFlags.Public|BindingFlags.Static, null, new Type[]{t}, null); if (meth != null && (meth.Attributes & MethodAttributes.SpecialName) != 0 && meth.ReturnType == Typeob.Boolean){ meth = new JSMethodInfo(meth); return (bool)meth.Invoke(null, BindingFlags.SuppressChangeType, null, new Object[]{value}, null); } return true; case TypeCode.DBNull: return false; case TypeCode.Boolean: return ic.ToBoolean(null); case TypeCode.Char: return ic.ToChar(null) != (Char)0; case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: return ic.ToInt32(null) != 0; case TypeCode.UInt32: case TypeCode.Int64: return ic.ToInt64(null) != 0; case TypeCode.UInt64: return ic.ToUInt64(null) != 0; case TypeCode.Single: case TypeCode.Double: double d = ic.ToDouble(null); if (d != d) return false; else return d != 0; case TypeCode.Decimal: return ic.ToDecimal(null) != (Decimal)0; case TypeCode.DateTime: return true; case TypeCode.String: return ic.ToString(null).Length != 0; } return false; //should never get here }
static int Diff(IConvertible val1, IConvertible val2) { ulong diff; switch (val1.GetTypeCode()) { case TypeCode.UInt64: diff = val2.ToUInt64(null) - val1.ToUInt64(null); break; case TypeCode.Int64: diff = (ulong)(val2.ToInt64(null) - val1.ToInt64(null)); break; case TypeCode.UInt32: diff = val2.ToUInt32(null) - val1.ToUInt32(null); break; default: diff = (ulong)(val2.ToInt32(null) - val1.ToInt32(null)); break; } if (diff >= int.MaxValue) return int.MaxValue; else return (int)diff; }
public void SetAsIConvertible(IConvertible value) { Debug.Assert(IsEmpty); // The setter can only be called once as VariantClear might be needed otherwise TypeCode tc = value.GetTypeCode(); CultureInfo ci = CultureInfo.CurrentCulture; switch (tc) { case TypeCode.Empty: break; case TypeCode.Object: AsUnknown = value; break; case TypeCode.DBNull: SetAsNull(); break; case TypeCode.Boolean: AsBool = value.ToBoolean(ci); break; case TypeCode.Char: AsUi2 = value.ToChar(ci); break; case TypeCode.SByte: AsI1 = value.ToSByte(ci); break; case TypeCode.Byte: AsUi1 = value.ToByte(ci); break; case TypeCode.Int16: AsI2 = value.ToInt16(ci); break; case TypeCode.UInt16: AsUi2 = value.ToUInt16(ci); break; case TypeCode.Int32: AsI4 = value.ToInt32(ci); break; case TypeCode.UInt32: AsUi4 = value.ToUInt32(ci); break; case TypeCode.Int64: AsI8 = value.ToInt64(ci); break; case TypeCode.UInt64: AsI8 = value.ToInt64(ci); break; case TypeCode.Single: AsR4 = value.ToSingle(ci); break; case TypeCode.Double: AsR8 = value.ToDouble(ci); break; case TypeCode.Decimal: AsDecimal = value.ToDecimal(ci); break; case TypeCode.DateTime: AsDate = value.ToDateTime(ci); break; case TypeCode.String: AsBstr = value.ToString(ci); break; default: throw Assert.Unreachable; } }
protected void EncodeConvertible(IConvertible value, Stream output) { output.WriteByte((byte)value.GetTypeCode()); byte[] result; switch (value.GetTypeCode()) { // the following encode directly on the stream case TypeCode.Boolean: output.WriteByte((byte)((bool)value ? 1 : 0)); return; case TypeCode.Byte: output.WriteByte(value.ToByte(null)); return; case TypeCode.SByte: output.WriteByte((byte)(value.ToSByte(null) + 128)); return; case TypeCode.Object: formatter.Serialize(output, value); return; case TypeCode.String: { long lengthPosition = output.Position; output.Write(new byte[4], 0, 4); StreamWriter w = new StreamWriter(output, Encoding.UTF8); w.Write((string)value); w.Flush(); long savedPosition = output.Position; uint payloadLength = (uint)(output.Position - lengthPosition - 4); output.Position = lengthPosition; output.Write(DataConverter.Converter.GetBytes(payloadLength), 0, 4); output.Position = savedPosition; return; } // the following obtain byte arrays which are dumped below case TypeCode.Char: result = DataConverter.Converter.GetBytes(value.ToChar(null)); break; case TypeCode.Single: result = DataConverter.Converter.GetBytes(value.ToSingle(null)); break; case TypeCode.Double: result = DataConverter.Converter.GetBytes(value.ToDouble(null)); break; case TypeCode.Int16: result = DataConverter.Converter.GetBytes(value.ToInt16(null)); break; case TypeCode.Int32: result = DataConverter.Converter.GetBytes(value.ToInt32(null)); break; case TypeCode.Int64: result = DataConverter.Converter.GetBytes(value.ToInt64(null)); break; case TypeCode.UInt16: result = DataConverter.Converter.GetBytes(value.ToUInt16(null)); break; case TypeCode.UInt32: result = DataConverter.Converter.GetBytes(value.ToUInt32(null)); break; case TypeCode.UInt64: result = DataConverter.Converter.GetBytes(value.ToUInt64(null)); break; case TypeCode.DateTime: result = DataConverter.Converter.GetBytes(((DateTime)value).ToBinary()); break; default: throw new MarshallingException("Unhandled form of IConvertible: " + value.GetTypeCode()); } output.Write(result, 0, result.Length); }
internal static int ToInt32(object value, IConvertible ic) { switch (GetTypeCode(value, ic)) { case TypeCode.Empty: return 0; case TypeCode.Object: case TypeCode.DateTime: { object obj2 = ToPrimitive(value, PreferredType.Number, ref ic); if (obj2 == value) { return 0; } return ToInt32(obj2, ic); } case TypeCode.DBNull: return 0; case TypeCode.Boolean: if (ic.ToBoolean(null)) { return 1; } return 0; case TypeCode.Char: return ic.ToChar(null); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: return ic.ToInt32(null); case TypeCode.UInt32: case TypeCode.Int64: return (int) ic.ToInt64(null); case TypeCode.UInt64: return (int) ic.ToUInt64(null); case TypeCode.Single: case TypeCode.Double: return (int) Runtime.DoubleToInt64(ic.ToDouble(null)); case TypeCode.Decimal: return (int) Runtime.UncheckedDecimalToInt64(ic.ToDecimal(null)); case TypeCode.String: return (int) Runtime.DoubleToInt64(ToNumber(ic.ToString(null))); } return 0; }
private object ExecuteBinaryOperator(IConvertible left, IConvertible right, CodeBinaryOperatorType op) { TypeCode typeCode = left.GetTypeCode(); TypeCode code2 = right.GetTypeCode(); TypeCode[] codeArray = new TypeCode[] { TypeCode.Byte, TypeCode.Char, TypeCode.Int16, TypeCode.UInt16, TypeCode.Int32, TypeCode.UInt32, TypeCode.Int64, TypeCode.UInt64 }; int num = -1; int num2 = -1; for (int i = 0; i < codeArray.Length; i++) { if (typeCode == codeArray[i]) { num = i; } if (code2 == codeArray[i]) { num2 = i; } if ((num != -1) && (num2 != -1)) { break; } } if ((num == -1) || (num2 == -1)) { return left; } int index = Math.Max(num, num2); object obj2 = left; switch (codeArray[index]) { case TypeCode.Char: { char ch = left.ToChar(null); char ch2 = right.ToChar(null); if (op != CodeBinaryOperatorType.BitwiseOr) { obj2 = ch & ch2; break; } obj2 = ch | ch2; break; } case TypeCode.Byte: { byte num5 = left.ToByte(null); byte num6 = right.ToByte(null); if (op != CodeBinaryOperatorType.BitwiseOr) { obj2 = num5 & num6; break; } obj2 = num5 | num6; break; } case TypeCode.Int16: { short num7 = left.ToInt16(null); short num8 = right.ToInt16(null); if (op != CodeBinaryOperatorType.BitwiseOr) { obj2 = num7 & num8; break; } obj2 = (short) (((ushort) num7) | ((ushort) num8)); break; } case TypeCode.UInt16: { ushort num9 = left.ToUInt16(null); ushort num10 = right.ToUInt16(null); if (op != CodeBinaryOperatorType.BitwiseOr) { obj2 = num9 & num10; break; } obj2 = num9 | num10; break; } case TypeCode.Int32: { int num11 = left.ToInt32(null); int num12 = right.ToInt32(null); if (op != CodeBinaryOperatorType.BitwiseOr) { obj2 = num11 & num12; break; } obj2 = num11 | num12; break; } case TypeCode.UInt32: { uint num13 = left.ToUInt32(null); uint num14 = right.ToUInt32(null); if (op != CodeBinaryOperatorType.BitwiseOr) { obj2 = num13 & num14; break; } obj2 = num13 | num14; break; } case TypeCode.Int64: { long num15 = left.ToInt64(null); long num16 = right.ToInt64(null); if (op != CodeBinaryOperatorType.BitwiseOr) { obj2 = num15 & num16; break; } obj2 = num15 | num16; break; } case TypeCode.UInt64: { ulong num17 = left.ToUInt64(null); ulong num18 = right.ToUInt64(null); if (op != CodeBinaryOperatorType.BitwiseOr) { obj2 = num17 & num18; break; } obj2 = num17 | num18; break; } } if ((obj2 != left) && (left is Enum)) { obj2 = Enum.ToObject(left.GetType(), obj2); } return obj2; }
internal static bool ToBoolean(object value, IConvertible ic) { switch (GetTypeCode(value, ic)) { case TypeCode.Empty: return false; case TypeCode.Object: { if ((value is Microsoft.JScript.Missing) || (value is System.Reflection.Missing)) { return false; } Type type = value.GetType(); MethodInfo method = type.GetMethod("op_True", BindingFlags.ExactBinding | BindingFlags.Public | BindingFlags.Static, null, new Type[] { type }, null); if (((method != null) && ((method.Attributes & MethodAttributes.SpecialName) != MethodAttributes.PrivateScope)) && (method.ReturnType == typeof(bool))) { method = new JSMethodInfo(method); return (bool) method.Invoke(null, BindingFlags.SuppressChangeType, null, new object[] { value }, null); } return true; } case TypeCode.DBNull: return false; case TypeCode.Boolean: return ic.ToBoolean(null); case TypeCode.Char: return (ic.ToChar(null) != '\0'); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: return (ic.ToInt32(null) != 0); case TypeCode.UInt32: case TypeCode.Int64: return (ic.ToInt64(null) != 0L); case TypeCode.UInt64: return (ic.ToUInt64(null) != 0L); case TypeCode.Single: case TypeCode.Double: { double num = ic.ToDouble(null); return ((num == num) && !(num == 0.0)); } case TypeCode.Decimal: return (ic.ToDecimal(null) != 0M); case TypeCode.DateTime: return true; case TypeCode.String: return (ic.ToString(null).Length != 0); } return false; }
internal static double ToNumber(object value, IConvertible ic) { switch (GetTypeCode(value, ic)) { case TypeCode.Empty: return double.NaN; case TypeCode.Object: case TypeCode.DateTime: { object obj2 = ToPrimitive(value, PreferredType.Number, ref ic); if (obj2 == value) { return double.NaN; } return ToNumber(obj2, ic); } case TypeCode.DBNull: return 0.0; case TypeCode.Boolean: return (ic.ToBoolean(null) ? ((double) 1) : ((double) 0)); case TypeCode.Char: return (double) ic.ToChar(null); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: return (double) ic.ToInt32(null); case TypeCode.UInt32: case TypeCode.Int64: return (double) ic.ToInt64(null); case TypeCode.UInt64: return (double) ic.ToUInt64(null); case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: return ic.ToDouble(null); case TypeCode.String: return ToNumber(ic.ToString(null)); } return 0.0; }