Beispiel #1
0
        protected override Expression VisitMethodCall(MethodCallExpression node)
        {
            if (node.Method.DeclaringType == typeof(WhereType))
            {
                if (node.Arguments.Count == 3 && node.Method.Name.Contains("Between"))
                {
                    FunExpression.Append("(");
                    Operator = WhereType.GetOperator(node.Method.Name);
                    Visit(node.Arguments[0]);
                    FunExpression.AppendFormat(" {0} ", Operator);
                    Visit(node.Arguments[1]);
                    FunExpression.AppendFormat(" AND ");
                    Visit(node.Arguments[2]);
                    FunExpression.Append(")");
                }
                else if (node.Arguments.Count == 2)
                {
                    FunExpression.Append("(");
                    Visit(node.Arguments[0]);
                    Operator = WhereType.GetOperator(node.Method.Name);
                    FunExpression.AppendFormat(" {0} ", Operator);
                    Visit(node.Arguments[1]);
                    FunExpression.Append(")");
                }
                else if (node.Arguments.Count == 1)
                {
                    FunExpression.Append("(");
                    Visit(node.Arguments[0]);
                    Operator = WhereType.GetOperator(node.Method.Name);
                    FunExpression.AppendFormat(" {0} ", Operator);
                    FunExpression.Append(")");
                }
            }
            else if (node.Method.GetCustomAttributes(typeof(FunctionAttribute), true).Length > 0)
            {
                FunExpression.AppendFormat("{0}(", node.Method.Name.ToUpper());
                var parameters = node.Method.GetParameters();
                for (var i = 0; i < node.Arguments.Count; i++)
                {
                    if (parameters[i].GetCustomAttributes(typeof(KeyParameterAttribute), true).Length > 0)
                    {
                        KeyParameter = true;
                    }
                    Visit(node.Arguments[i]);
                    if (i + 1 < node.Arguments.Count)
                    {
                        FunExpression.Append(",");
                    }
                }
                FunExpression.Append(")");
            }
            else
            {
                var value = Expression.Lambda(node).Compile().DynamicInvoke();
                SetValue(value);
            }

            return(node);
        }
Beispiel #2
0
 protected override Expression VisitBinary(BinaryExpression node)
 {
     WhereExpression.Append("(");
     Visit(node.Left);
     Operator = WhereType.GetOperator(node.NodeType);
     WhereExpression.AppendFormat(" {0} ", Operator);
     Visit(node.Right);
     WhereExpression.Append(")");
     return(node);
 }
Beispiel #3
0
 protected override Expression VisitUnary(UnaryExpression node)
 {
     if (node.NodeType == ExpressionType.Not)
     {
         FunExpression.Append(WhereType.GetOperator(node.NodeType));
         Visit(node.Operand);
     }
     else
     {
         Visit(node.Operand);
     }
     return(node);
 }
Beispiel #4
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);
 }
Beispiel #5
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());
 }
Beispiel #6
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);
 }