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