Ejemplo n.º 1
0
        protected override Expression VisitMethodCall(MethodCallExpression node)
        {
            var result = new FunctionExpressionResovle(node).Resovle();

            _textBuilder.Append($"{result}{_asc},");
            return(node);
        }
 protected override Expression VisitNew(NewExpression node)
 {
     for (int i = 0; i < node.Arguments.Count; i++)
     {
         var item   = node.Arguments[i];
         var column = node.Members[i].Name;
         if (item is MemberExpression member)
         {
             var name = GetColumnName(member.Member.DeclaringType, member.Member.Name);
             if (name != column)
             {
                 _textBuilder.Append($"{name} AS {column}");
             }
             else
             {
                 _textBuilder.Append($"{name}");
             }
         }
         else if (item is MethodCallExpression)
         {
             var expression = new FunctionExpressionResovle(item).Resovle();
             _textBuilder.Append($"{expression} AS {column}");
         }
         if (i != node.Arguments.Count - 1)
         {
             _textBuilder.Append(",");
         }
     }
     return(node);
 }
        protected override Expression VisitMemberInit(MemberInitExpression node)
        {
            for (int i = 0; i < node.Bindings.Count; i++)
            {
                var item = node.Bindings[i] as MemberAssignment;

                if (item.Expression is MemberExpression member)
                {
                    var name = GetColumnName(member.Member.DeclaringType, member.Member.Name);
                    _textBuilder.Append($"{name} AS {item.Member.Name}");
                }
                else if (item.Expression is MethodCallExpression)
                {
                    var expression = new FunctionExpressionResovle(item.Expression).Resovle();
                    _textBuilder.Append($"{expression} AS {item.Member.Name}");
                }
                if (i != node.Bindings.Count - 1)
                {
                    _textBuilder.Append(",");
                }
            }
            return(node);
        }
Ejemplo n.º 4
0
 protected override Expression VisitMethodCall(MethodCallExpression node)
 {
     if (node.Method.DeclaringType == typeof(Operator))
     {
         if (node.Arguments.Count == 2)
         {
             _textBuilder.Append("(");
             SetParameterName(node.Arguments[0] as MemberExpression);
             var type = Operator.ResovleExpressionType(node.Method.Name);
             _textBuilder.Append($" {type} ");
             var value = VisitConstantValue(node.Arguments[1]);
             if (node.Method.Name == nameof(Operator.StartsWith) || node.Method.Name == nameof(Operator.NotStartsWith))
             {
                 SetParameterValue(Expression.Constant($"{value}%", typeof(string)));
             }
             else if (node.Method.Name == nameof(Operator.EndsWith) || node.Method.Name == nameof(Operator.NotEndsWith))
             {
                 SetParameterValue(Expression.Constant($"%{value}", typeof(string)));
             }
             else if (node.Method.Name == nameof(Operator.Contains) || node.Method.Name == nameof(Operator.NotContains))
             {
                 SetParameterValue(Expression.Constant($"%{value}%", typeof(string)));
             }
             else
             {
                 SetParameterValue(Expression.Constant(value));
             }
             _textBuilder.Append(")");
         }
     }
     else if (IsLikeExpression(node))
     {
         _textBuilder.Append("(");
         object value = null;
         if (IsParameterExpression(node.Object))
         {
             SetParameterName(node.Object as MemberExpression);
             value = VisitConstantValue(node.Arguments[0]);
         }
         else
         {
             SetParameterName(node.Arguments[0] as MemberExpression);
             value = VisitConstantValue(node.Object);
         }
         if (_isNotExpression)
         {
             _isNotExpression = false;
             _textBuilder.Append(" NOT LIKE ");
         }
         else
         {
             _textBuilder.Append(" LIKE ");
         }
         if (node.Method.Name == nameof(string.Contains))
         {
             SetParameterValue(Expression.Constant($"%{value}%"));
         }
         else if (node.Method.Name == nameof(string.StartsWith))
         {
             SetParameterValue(Expression.Constant($"{value}%"));
         }
         else
         {
             SetParameterValue(Expression.Constant($"%{value}"));
         }
         _textBuilder.Append(")");
     }
     else if (IsInExpression(node))
     {
         _textBuilder.Append("(");
         SetParameterName(node.Arguments[1] as MemberExpression);
         if (_isNotExpression)
         {
             _isNotExpression = false;
             _textBuilder.Append(" NOT IN ");
         }
         else
         {
             _textBuilder.Append(" IN ");
         }
         SetParameterValue(node.Arguments[0] as MemberExpression);
         _textBuilder.Append(")");
     }
     else if (node.Method.DeclaringType.GetCustomAttribute(typeof(FunctionAttribute), true) != null)
     {
         var function = new FunctionExpressionResovle(node).Resovle();
         _textBuilder.Append(function);
     }
     else
     {
         SetParameterValue(node);
     }
     return(node);
 }