protected override Expression VisitMethodCall(MethodCallExpression node) { if (node.Method.DeclaringType == typeof(ConditionType)) { if (node.Arguments.Count == 3 && node.Method.Name.Contains("Between")) { WhereExpression.Append("("); CurrentCondition = ConditionType.GetOperator(node.Method.Name); Visit(node.Arguments[0]); WhereExpression.AppendFormat(" {0} ", CurrentCondition); Visit(node.Arguments[1]); WhereExpression.AppendFormat(" AND "); Visit(node.Arguments[2]); WhereExpression.Append(")"); } else if (node.Arguments.Count == 2) { WhereExpression.Append("("); Visit(node.Arguments[0]); CurrentCondition = ConditionType.GetOperator(node.Method.Name); WhereExpression.AppendFormat(" {0} ", CurrentCondition); Visit(node.Arguments[1]); WhereExpression.Append(")"); } else if (node.Arguments.Count == 1) { WhereExpression.Append("("); Visit(node.Arguments[0]); CurrentCondition = ConditionType.GetOperator(node.Method.Name); WhereExpression.AppendFormat(" {0} ", CurrentCondition); WhereExpression.Append(")"); } } else if (node.Method.GetCustomAttributes(typeof(FunctionAttribute), true).Length > 0) { WhereExpression.Append(new FunctionVisitor <T>().Build(Param, node, false)); SetName("", node.Method.Name); } else { //var value = Expression.Lambda(node).Compile().DynamicInvoke(); SetValue(node); } return(node); }
/// <summary> /// 构建表达式 /// </summary> /// <param name="param"></param> /// <param name="expressionList"></param> /// <returns></returns> internal string Build(Dictionary <string, object> param, List <QueryableExpression> expressionList) { Param = param; foreach (var item in expressionList) { if ((!item.Equals(expressionList.First()))) { WhereExpression.AppendFormat(" {0} ", ConditionType.GetOperator(item.ExpressType)); } if (!string.IsNullOrEmpty(item.StringWhere)) { WhereExpression.Append(item.StringWhere); continue; } Visit(item.LambdaWhere); } return(WhereExpression.ToString()); }
protected override Expression VisitUnary(UnaryExpression node) { if (node.NodeType == ExpressionType.Not) { WhereExpression.Append(ConditionType.GetOperator(node.NodeType)); Visit(node.Operand); } else if (node.Operand.NodeType == ExpressionType.New) { //var value = Expression.Lambda(node).Compile().DynamicInvoke(); SetValue(node); } else { Visit(node.Operand); } return(node); }