public Object EvaluatePlus(Object v1, Object v2) { if (v1 is Int32 && v2 is Int32) { return(Plus.DoOp((Int32)v1, (Int32)v2)); } else if (v1 is Double && v2 is Double) { return(Plus.DoOp((Double)v1, (Double)v2)); } else { return(this.EvaluatePlus2(v1, v2)); } }
private Object EvaluatePlus2(Object v1, Object v2) { IConvertible ic1 = Convert.GetIConvertible(v1); IConvertible ic2 = Convert.GetIConvertible(v2); TypeCode t1 = Convert.GetTypeCode(v1, ic1); TypeCode t2 = Convert.GetTypeCode(v2, ic2); switch (t1) { case TypeCode.Empty: return(Plus.DoOp(v1, v2)); case TypeCode.DBNull: switch (t2) { case TypeCode.Empty: return(Double.NaN); case TypeCode.DBNull: return(0); case TypeCode.Boolean: case TypeCode.Char: case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: return(ic2.ToInt32(null)); case TypeCode.UInt32: return(ic2.ToUInt32(null)); case TypeCode.Int64: return(ic2.ToInt64(null)); case TypeCode.UInt64: return(ic2.ToUInt64(null)); case TypeCode.Single: case TypeCode.Double: return(ic2.ToDouble(null)); case TypeCode.Object: case TypeCode.Decimal: case TypeCode.DateTime: break; case TypeCode.String: return("null" + ic2.ToString(null)); } break; case TypeCode.Char: { int val = ic1.ToInt32(null); switch (t2) { case TypeCode.Empty: return(Double.NaN); case TypeCode.DBNull: return(val); case TypeCode.Boolean: case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: return(((IConvertible)Plus.DoOp(val, ic2.ToInt32(null))).ToChar(null)); case TypeCode.UInt32: case TypeCode.Int64: return(((IConvertible)Plus.DoOp((long)val, ic2.ToInt64(null))).ToChar(null)); case TypeCode.UInt64: return(((IConvertible)Plus.DoOp((ulong)val, ic2.ToUInt64(null))).ToChar(null)); case TypeCode.Single: case TypeCode.Double: checked { return((char)(int)(Convert.CheckIfDoubleIsInteger((double)Plus.DoOp((double)val, ic2.ToDouble(null))))); } case TypeCode.Object: case TypeCode.Decimal: case TypeCode.DateTime: return(Plus.DoOp(v1, v2)); case TypeCode.Char: case TypeCode.String: return(ic1.ToString(null) + ic2.ToString(null)); } break; } case TypeCode.Boolean: case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: { int val = ic1.ToInt32(null); switch (t2) { case TypeCode.Empty: return(Double.NaN); case TypeCode.DBNull: return(val); case TypeCode.Char: return(((IConvertible)Plus.DoOp(val, ic2.ToInt32(null))).ToChar(null)); case TypeCode.Boolean: case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: return(Plus.DoOp(val, ic2.ToInt32(null))); case TypeCode.UInt32: case TypeCode.Int64: return(Plus.DoOp((long)val, ic2.ToInt64(null))); case TypeCode.UInt64: if (val >= 0) { return(Plus.DoOp((ulong)val, ic2.ToUInt64(null))); } else { return(Plus.DoOp((double)val, ic2.ToDouble(null))); } case TypeCode.Single: case TypeCode.Double: return(Plus.DoOp((double)val, ic2.ToDouble(null))); case TypeCode.Object: case TypeCode.Decimal: case TypeCode.DateTime: break; case TypeCode.String: return(Convert.ToString(v1) + ic2.ToString(null)); } break; } case TypeCode.UInt32: { uint val = ic1.ToUInt32(null); switch (t2) { case TypeCode.Empty: return(Double.NaN); case TypeCode.DBNull: return(val); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.Int32: int val2 = ic2.ToInt32(null); if (val2 >= 0) { return(Plus.DoOp(val, (uint)val2)); } else { return(Plus.DoOp((long)val, (long)val2)); } case TypeCode.Int64: return(Plus.DoOp((long)val, ic2.ToInt64(null))); case TypeCode.Char: return(((IConvertible)Plus.DoOp(val, ic2.ToUInt32(null))).ToChar(null)); case TypeCode.Boolean: case TypeCode.UInt16: case TypeCode.UInt32: return(Plus.DoOp(val, ic2.ToUInt32(null))); case TypeCode.UInt64: return(Plus.DoOp((ulong)val, ic2.ToUInt64(null))); case TypeCode.Single: case TypeCode.Double: return(Plus.DoOp((double)val, ic2.ToDouble(null))); case TypeCode.Object: case TypeCode.Decimal: case TypeCode.DateTime: break; case TypeCode.String: return(Convert.ToString(v1) + ic2.ToString(null)); } break; } case TypeCode.Int64: { long val = ic1.ToInt64(null); switch (t2) { case TypeCode.Empty: return(Double.NaN); case TypeCode.DBNull: return(val); case TypeCode.Char: return(((IConvertible)Plus.DoOp(val, ic2.ToInt64(null))).ToChar(null)); case TypeCode.Boolean: case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: return(Plus.DoOp(val, ic2.ToInt64(null))); case TypeCode.UInt64: if (val >= 0) { return(Plus.DoOp((ulong)val, ic2.ToUInt64(null))); } else { return(Plus.DoOp((double)val, ic2.ToDouble(null))); } case TypeCode.Single: case TypeCode.Double: return(Plus.DoOp((double)val, ic2.ToDouble(null))); case TypeCode.Object: case TypeCode.Decimal: case TypeCode.DateTime: break; case TypeCode.String: return(Convert.ToString(v1) + ic2.ToString(null)); } break; } case TypeCode.UInt64: { ulong val = ic1.ToUInt64(null); switch (t2) { case TypeCode.Empty: return(Double.NaN); case TypeCode.DBNull: return(val); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: long val2 = ic2.ToInt64(null); if (val2 >= 0) { return(Plus.DoOp(val, (ulong)val2)); } else { return(Plus.DoOp((double)val, (double)val2)); } case TypeCode.Char: return(((IConvertible)Plus.DoOp(val, ic2.ToUInt64(null))).ToChar(null)); case TypeCode.UInt16: case TypeCode.Boolean: case TypeCode.UInt32: case TypeCode.UInt64: return(Plus.DoOp(val, ic2.ToUInt64(null))); case TypeCode.Single: case TypeCode.Double: return(Plus.DoOp((double)val, ic2.ToDouble(null))); case TypeCode.Object: case TypeCode.Decimal: case TypeCode.DateTime: break; case TypeCode.String: return(Convert.ToString(v1) + ic2.ToString(null)); } break; } case TypeCode.Single: case TypeCode.Double: { double d = ic1.ToDouble(null); switch (t2) { case TypeCode.Empty: return(Double.NaN); case TypeCode.DBNull: return(ic1.ToDouble(null)); case TypeCode.Char: return(System.Convert.ToChar(System.Convert.ToInt32((d + (double)ic2.ToInt32(null))))); case TypeCode.Boolean: case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: return(d + (double)ic2.ToInt32(null)); case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: case TypeCode.Single: case TypeCode.Double: return(d + ic2.ToDouble(null)); case TypeCode.Object: case TypeCode.Decimal: case TypeCode.DateTime: break; case TypeCode.String: return(new ConcatString(Convert.ToString(d), ic2.ToString(null))); } break; } case TypeCode.Object: case TypeCode.Decimal: case TypeCode.DateTime: break; case TypeCode.String: switch (t2) { case TypeCode.Object: break; case TypeCode.String: if (v1 is ConcatString) { return(new ConcatString((ConcatString)v1, ic2.ToString(null))); } else { return(new ConcatString(ic1.ToString(null), ic2.ToString(null))); } default: if (v1 is ConcatString) { return(new ConcatString((ConcatString)v1, Convert.ToString(v2))); } else { return(new ConcatString(ic1.ToString(null), Convert.ToString(v2))); } } break; } MethodInfo oper = this.GetOperator(v1 == null ? Typeob.Empty : v1.GetType(), v2 == null ? Typeob.Empty : v2.GetType()); if (oper != null) { return(oper.Invoke(null, (BindingFlags)0, JSBinder.ob, new Object[] { v1, v2 }, null)); } else { return(Plus.DoOp(v1, v2)); } }