private static bool SatisfyCalcCondition( Func <Expression, Expression, BinaryExpression> func, object x, object y, out object output) { output = null; if (func.Method.Name.Equals("Divide")) { return(false); } if (LogicSharp.IsNumeric(x) && LogicSharp.IsNumeric(y)) { double xDoubleVal; double yDoubleVal; bool isXDouble = LogicSharp.IsDouble(x, out xDoubleVal); bool isYDouble = LogicSharp.IsDouble(y, out yDoubleVal); if (isXDouble || isYDouble) { var xExpr = Expression.Constant(xDoubleVal); var yExpr = Expression.Constant(yDoubleVal); var rExpr = func(xExpr, yExpr); output = Expression.Lambda <Func <double> >(rExpr).Compile().Invoke(); int iResult; if (LogicSharp.IsInt(output, out iResult)) { output = iResult; return(true); } return(true); } } return(false); }
public static object Calculate(Func <Expression, Expression, BinaryExpression> func, object x, object y) { double xDoubleVal; double yDoubleVal; bool isXDouble = LogicSharp.IsDouble(x, out xDoubleVal); bool isYDouble = LogicSharp.IsDouble(y, out yDoubleVal); if (isXDouble || isYDouble) { var xExpr = Expression.Constant(xDoubleVal); var yExpr = Expression.Constant(yDoubleVal); var rExpr = func(xExpr, yExpr); var result = Expression.Lambda <Func <double> >(rExpr).Compile().Invoke(); int iResult; if (LogicSharp.IsInt(result, out iResult)) { return(iResult); } else { return(result); } } else { return(null); } }
public override string ToString() { double dNum; bool isNum = LogicSharp.IsDouble(Rhs, out dNum); if (isNum) { int iNum; bool isInteger = LogicSharp.IsInt(Rhs, out iNum); if (isInteger) { return(base.ToString()); } double roundD = Math.Round(dNum, 4); return(string.Format("{0}={1}", Lhs, roundD)); } return(base.ToString()); }