static Expose Addition(Expose left, object right) { try { if (IsNumber(left) && IsNumber(right)) { var d = ToDecimal(left) + ToDecimal(right); return(Expose.FromObject(ToDecimal(left) + ToDecimal(right))); } return(Expose.FromType(left.Type).Call("op_Addition", left.Value, right)); } catch { } object lv = ReferenceEquals(left, null) ? null : left.Value; if (lv is string || right is string) { string ls = ReferenceEquals(lv, null) ? "" : lv.ToString(); string rs = ReferenceEquals(right, null) ? "" : right.ToString(); return(Expose.FromObject(ls + rs)); } try { return(Expose.FromObject(ToDecimal(left) + ToDecimal(right))); } catch { } return(null); }
static Expose Subtraction(Expose left, object right) { try { return(Expose.FromType(left.Type).Call("op_Subtraction", left.Value, right)); } catch { } try { return(Expose.FromObject(ToDecimal(left) - ToDecimal(right))); } catch { } return(null); }
static bool LessThan(Expose left, object right) { try { return((bool)Expose.FromType(left.Type).Call("op_LessThan", left.Value, right).Value); } catch { } try { return(ToDecimal(left) < ToDecimal(right)); } catch { return(Expose.Compare(left, right) < 0); } }
static Expose DoOperation(Expose left, object right, Operation op) { try { return(Expose.FromType(left.Type).Call(op.ToString(), left.Value, right)); } catch { } try { switch (op) { case Operation.op_Addition: return(Expose.FromObject(ToDecimal(left) + ToDecimal(right))); case Operation.op_Subtraction: return(Expose.FromObject(ToDecimal(left) - ToDecimal(right))); case Operation.op_Equality: return(Expose.FromObject(ToDecimal(left) == ToDecimal(right))); case Operation.op_Inequality: return(Expose.FromObject(ToDecimal(left) != ToDecimal(right))); case Operation.op_GreaterThan: return(Expose.FromObject(ToDecimal(left) > ToDecimal(right))); case Operation.op_LessThan: return(Expose.FromObject(ToDecimal(left) < ToDecimal(right))); case Operation.op_GreaterThanOrEqual: return(Expose.FromObject(ToDecimal(left) <= ToDecimal(right))); case Operation.op_LessThanOrEqual: return(Expose.FromObject(ToDecimal(left) >= ToDecimal(right))); case Operation.op_BitwiseAnd: return(Expose.FromObject(ToInt(left) & ToInt(right))); case Operation.op_BitwiseOr: return(Expose.FromObject(ToInt(left) | ToInt(right))); case Operation.op_Division: return(Expose.FromObject(ToDecimal(left) / ToDecimal(right))); case Operation.op_Modulus: return(Expose.FromObject(ToDecimal(left) % ToDecimal(right))); case Operation.op_Multiply: return(Expose.FromObject(ToDecimal(left) * ToDecimal(right))); case Operation.op_LeftShift: return(Expose.FromObject(ToInt(left) << ToInt(right))); case Operation.op_RightShift: return(Expose.FromObject(ToInt(left) >> ToInt(right))); case Operation.op_ExclusiveOr: return(Expose.FromObject(ToInt(left) ^ ToInt(right))); case Operation.op_UnaryNegation: break; case Operation.op_UnaryPlus: break; case Operation.op_LogicalNot: break; case Operation.op_OnesComplement: break; case Operation.op_False: break; case Operation.op_True: break; case Operation.op_Increment: break; case Operation.op_Decrement: break; } } catch { } return(null); }