private void MethodCallLike(MethodCallExpression exp, SqlVistorFlag flag)
 {
     Visit(exp.Object, flag);
     flag.Append(GetUnaryOperater(flag.UnaryType));
     flag.Append(" LIKE CONCAT('%',");
     VisitRight(exp.Arguments[0], flag);
     flag.Append(",'%')");
 }
Beispiel #2
0
 protected virtual void VisitMember(MemberExpression exp, SqlVistorFlag flag)
 {
     if (flag.IsRight)
     {
         var proParaName = GetParaName(exp.Member.Name);
         flag.Append(proParaName);
         AddMemberProperty(proParaName, exp.Member.DeclaringType.GetProperty(exp.Member.Name));
     }
     else
     {
         flag.Append(exp.Member.Name);
     }
 }
        protected virtual void VisitConstant(ConstantExpression c, SqlVistorFlag flag)
        {
            var value = c.Value ?? "null";

            if (flag.IsRight)
            {
                var paraName = flag.GetCustomParaName();
                flag.Append(paraName);

                AddParameter(paraName, c.Type == typeof(bool) ? ((bool)value ? 1 : 0) : value);
            }
            else
            {
                flag.Append(value.ToString());
            }
        }
Beispiel #4
0
        protected virtual void VisitConstant(ConstantExpression c, SqlVistorFlag flag)
        {
            var value = c.Value ?? "null";

            if (flag.IsRight)
            {
                const string parameterPre = "ConstPara";
                var          paraName     = GetParaName(parameterPre, true);
                flag.Append(paraName);
                AddParameter(paraName, value);
            }
            else
            {
                flag.Append(value.ToString());
            }
        }
        protected virtual void VisitMember(MemberExpression exp, SqlVistorFlag flag)
        {
            if (exp.Expression != null &&
                exp.Expression.NodeType == ExpressionType.Parameter)
            {
                if (flag.IsRight)
                {
                    var proParaName = flag.GetParaName(exp.Member.Name);

                    flag.Append(proParaName);

                    AddMemberProperty(proParaName, exp.Member.DeclaringType.GetProperty(exp.Member.Name));
                }
                else
                {
                    if (exp.Member.DeclaringType.GetTypeInfo().IsGenericType &&
                        exp.Member.DeclaringType.GetGenericTypeDefinition() == typeof(Nullable <>))
                    {
                        if (exp.Member.Name == "Value")
                        {
                            Visit(exp.Expression, flag);
                        }

                        if (exp.Member.Name != "HasValue")
                        {
                            return;
                        }

                        var doesNotEqualNull = Expression.MakeBinary(ExpressionType.NotEqual, exp.Expression,
                                                                     Expression.Constant(null));
                        Visit(doesNotEqualNull, flag);
                    }
                    else
                    {
                        flag.Append(flag.GetColName(exp.Member.Name));
                    }
                }
            }
            else if (exp.Expression != null && flag.IsRight)
            {
                var value = Expression.Lambda(exp).Compile().DynamicInvoke();
                Visit(Expression.Constant(value), flag);
            }
        }
        protected virtual void VisitNew(NewExpression nex, SqlVistorFlag flag)
        {
            for (var i = 0; i < nex.Members.Count; i++)
            {
                var arg    = nex.Arguments[i];
                var member = nex.Members[i];

                flag.Append(flag.GetColName(member.Name)).Append("=");
                VisitRight(arg, flag);
            }
        }
        protected virtual void VisitBinary(BinaryExpression exp, SqlVistorFlag flag)
        {
            var operand = GetBinaryOperater(exp.NodeType);

            if (exp.NodeType == ExpressionType.AndAlso ||
                exp.NodeType == ExpressionType.OrElse)
            {
                flag.Append("(");
                Visit(exp.Left, flag);
                flag.Append(") ").Append(operand).Append(" (");
                Visit(exp.Right, flag);
                flag.Append(")");
            }
            else
            {
                Visit(exp.Left, flag);
                flag.Append(operand);
                VisitRight(exp.Right, flag);
            }
        }
        protected virtual void VisitNew(NewExpression nex, SqlVistorFlag flag)
        {
            for (var i = 0; i < nex.Members.Count; i++)
            {
                var arg    = nex.Arguments[i];
                var member = nex.Members[i];
                flag.Append(string.Concat("`", member.Name, "`", "="), true);

                VisitRight(arg, flag);
            }
        }
 protected virtual void VisitMember(MemberExpression exp, SqlVistorFlag flag)
 {
     if (exp.Expression != null &&
         exp.Expression.NodeType == ExpressionType.Parameter)
     {
         if (flag.IsRight)
         {
             var proParaName = GetParaName(exp.Member.Name);
             flag.Append(proParaName);
             AddMemberProperty(proParaName, exp.Member.DeclaringType.GetProperty(exp.Member.Name));
         }
         else
         {
             if (exp.Member.DeclaringType.GetTypeInfo().IsGenericType &&
                 exp.Member.DeclaringType.GetGenericTypeDefinition() == typeof(Nullable <>))
             {
                 if (exp.Member.Name == "Value") //Can't use C# 6 yet: nameof(Nullable<bool>.Value)
                 {
                     Visit(exp.Expression, flag);
                 }
                 if (exp.Member.Name == "HasValue") //nameof(Nullable<bool>.HasValue)
                 {
                     var doesNotEqualNull = Expression.MakeBinary(ExpressionType.NotEqual, exp.Expression,
                                                                  Expression.Constant(null));
                     Visit(doesNotEqualNull, flag); // Nullable<T>.HasValue is equivalent to "!= null"
                 }
             }
             else
             {
                 flag.Append(string.Concat("`", exp.Member.Name, "`"), true);
             }
         }
     }
     else if (exp.Expression != null && flag.IsRight)
     {
         var value = Expression.Lambda(exp).Compile().DynamicInvoke();
         Visit(Expression.Constant(value), flag);
     }
 }