Exemplo n.º 1
0
 private void Select(MemberInitExpression expression, ExpressionParameter parameter, bool isSingle)
 {
     foreach (MemberBinding binding in expression.Bindings)
     {
         if (binding.BindingType != MemberBindingType.Assignment)
         {
             throw new NotSupportedException();
         }
         MemberAssignment memberAssignment = (MemberAssignment)binding;
         var memberName = memberAssignment.Member.Name;
         var item       = memberAssignment.Expression;
         ResolveNewExpressions(parameter, item, memberName);
     }
 }
Exemplo n.º 2
0
 protected void AppendMember(ExpressionParameter parameter, bool?isLeft, object appendValue)
 {
     Context.ParameterIndex++;
     if (isLeft == true)
     {
         appendValue += ExpressionConst.ExpressionReplace + parameter.BaseParameter.Index;
     }
     if (this.Context.Result.Contains(ExpressionConst.FormatSymbol))
     {
         this.Context.Result.Replace(ExpressionConst.FormatSymbol, appendValue.ObjToString());
     }
     else
     {
         this.Context.Result.Append(appendValue);
     }
 }
Exemplo n.º 3
0
        public MemberNoExpressionResolve(ExpressionParameter parameter) : base(parameter)
        {
            var    expression    = base.Expression as MemberExpression;
            var    isLeft        = parameter.IsLeft;
            object value         = null;
            var    isField       = expression.Member is System.Reflection.FieldInfo;
            var    isProperty    = expression.Member is System.Reflection.PropertyInfo;
            var    baseParameter = parameter.BaseParameter;
            var    isSetTempData = baseParameter.CommonTempData.HasValue() && baseParameter.CommonTempData.Equals(CommonTempDataType.Result);

            if (isField)
            {
                value = ExpressionTool.GetFiledValue(expression);
            }
            else if (isProperty)
            {
                value = ExpressionTool.GetPropertyValue(expression);
            }
            switch (base.Context.ResolveType)
            {
            case ResolveExpressType.WhereSingle:
            case ResolveExpressType.WhereMultiple:
            case ResolveExpressType.SelectSingle:
            case ResolveExpressType.SelectMultiple:
            case ResolveExpressType.Update:
                if (isSetTempData)
                {
                    baseParameter.CommonTempData = value;
                }
                else
                {
                    AppendValue(parameter, isLeft, value);
                }
                break;

            case ResolveExpressType.FieldSingle:
                break;

            case ResolveExpressType.FieldMultiple:
                break;

            default:
                break;
            }
        }
 private void Append(ExpressionParameter parameter, ExpressionType nodeType)
 {
     BaseParameter.ChildExpression = base.Expression;
     this.IsLeft = parameter.IsLeft;
     parameter.CommonTempData = CommonTempDataType.Append;
     if (nodeType == ExpressionType.Not)
     {
         AppendNot(parameter.CommonTempData);
     }
     if (nodeType == ExpressionType.Negate)
     {
         AppendNegate(parameter.CommonTempData);
     }
     base.Start();
     parameter.BaseParameter.CommonTempData  = parameter.CommonTempData;
     parameter.BaseParameter.ChildExpression = base.Expression;
     parameter.CommonTempData = null;
 }
Exemplo n.º 5
0
 private void NewValueType(ExpressionParameter parameter, NewExpression expression)
 {
     try
     {
         var value         = ExpressionTool.DynamicInvoke(expression);
         var isSetTempData = parameter.CommonTempData.HasValue() && parameter.CommonTempData.Equals(CommonTempDataType.Result);
         if (isSetTempData)
         {
             parameter.CommonTempData = value;
         }
         else
         {
             AppendValue(parameter, parameter.IsLeft, value);
         }
     }
     catch (Exception ex)
     {
         Check.Exception(expression.Type == UtilConstants.DateType, "ThrowNotSupportedException {0} ", ex.ToString());
     }
 }
        public TypeParameterExpressionReolve(ExpressionParameter parameter) : base(parameter)
        {
            var expression = (ParameterExpression)base.Expression;

            switch (parameter.Context.ResolveType)
            {
            case ResolveExpressType.WhereSingle:
                break;

            case ResolveExpressType.WhereMultiple:
                break;

            case ResolveExpressType.Update:
                parameter.BaseParameter.CommonTempData = expression.Name;
                break;

            case ResolveExpressType.SelectSingle:
            case ResolveExpressType.SelectMultiple:
                if (parameter.BaseParameter != null && parameter.BaseParameter.CurrentExpression.NodeType == ExpressionType.Lambda)
                {
                    this.Context.Result.Append(expression.Name + ".*");
                }
                else
                {
                    parameter.BaseParameter.CommonTempData = expression.Name;
                }
                break;

            case ResolveExpressType.FieldSingle:
                break;

            case ResolveExpressType.FieldMultiple:
                break;

            case ResolveExpressType.Join:
                break;

            default:
                break;
            }
        }
Exemplo n.º 7
0
 private void CusMethod(ExpressionParameter parameter, MethodCallExpression express, bool?isLeft)
 {
     try
     {
         var constValue = ExpressionTool.DynamicInvoke(express);
         parameter.BaseParameter.CommonTempData = constValue;
         var parameterName = base.AppendParameter(constValue);
         if (parameter.BaseParameter.CommonTempData != null && parameter.BaseParameter.CommonTempData.Equals(CommonTempDataType.Result))
         {
             this.Context.Result.Append(parameterName);
         }
         else
         {
             base.AppendValue(parameter, isLeft, parameterName);
         }
     }
     catch
     {
         Check.Exception(true, string.Format(ErrorMessage.MethodError, express.Method.Name));
     }
 }
        private void ResolveDateDate(ExpressionParameter parameter, bool?isLeft, MemberExpression expression)
        {
            var name = expression.Member.Name;
            var oldCommonTempDate = parameter.CommonTempData;

            parameter.CommonTempData = CommonTempDataType.Result;
            this.Expression          = expression.Expression;
            this.Start();
            var isConst = parameter.CommonTempData.GetType() == UtilConstants.DateType;

            if (isConst)
            {
                AppendValue(parameter, isLeft, parameter.CommonTempData.ObjToDate().Date);
            }
            else
            {
                var GetYear = new MethodCallExpressionModel()
                {
                    Args = new List <MethodCallExpressionArgs>()
                    {
                        new MethodCallExpressionArgs()
                        {
                            IsMember = true, MemberName = parameter.CommonTempData, MemberValue = parameter.CommonTempData
                        },
                        new MethodCallExpressionArgs()
                        {
                            MemberName = DateType.Year, MemberValue = DateType.Year
                        }
                    }
                };
                AppendMember(parameter, isLeft, GetToDate(this.Context.DbMehtods.MergeString(
                                                              this.GetDateValue(parameter.CommonTempData, DateType.Year),
                                                              "'-'",
                                                              this.GetDateValue(parameter.CommonTempData, DateType.Month),
                                                              "'-'",
                                                              this.GetDateValue(parameter.CommonTempData, DateType.Day))));
            }
            parameter.CommonTempData = oldCommonTempDate;
        }
 private void ResolveCallValue(ExpressionParameter parameter, ExpressionParameter baseParameter, MemberExpression expression, bool?isLeft, bool isSetTempData, bool isSingle)
 {
     try
     {
         baseParameter.ChildExpression = expression;
         string fieldName = string.Empty;
         if (isSetTempData)
         {
             var value = ExpressionTool.DynamicInvoke(expression);
             baseParameter.CommonTempData = value;
         }
         else
         {
             var value = ExpressionTool.DynamicInvoke(expression);
             base.AppendValue(parameter, isLeft, value);
         }
     }
     catch
     {
         Check.Exception(true, "Not Support {0}", expression.ToString());
     }
 }
        public ConditionalExpressionResolve(ExpressionParameter parameter) : base(parameter)
        {
            string name    = "IIF";
            var    express = base.Expression as ConditionalExpression;
            var    args    = new List <Expression>()
            {
                express.Test,
                express.IfTrue,
                express.IfFalse
            };
            var isLeft = parameter.IsLeft;
            MethodCallExpressionModel model = new MethodCallExpressionModel();

            model.Args = new List <MethodCallExpressionArgs>();
            switch (this.Context.ResolveType)
            {
            case ResolveExpressType.WhereSingle:
            case ResolveExpressType.WhereMultiple:
                Check.Exception(name == "GetSelfAndAutoFill", "SqlFunc.GetSelfAndAutoFill can only be used in Select.");
                base.Where(parameter, isLeft, name, args, model);
                break;

            case ResolveExpressType.SelectSingle:
            case ResolveExpressType.SelectMultiple:
            case ResolveExpressType.Update:
                base.Select(parameter, isLeft, name, args, model);
                break;

            case ResolveExpressType.FieldSingle:
            case ResolveExpressType.FieldMultiple:
                base.Field(parameter, isLeft, name, args, model);
                break;

            default:
                break;
            }
        }
Exemplo n.º 11
0
        public MemberConstExpressionResolve(ExpressionParameter parameter) : base(parameter)
        {
            var    expression    = base.Expression as MemberExpression;
            var    isLeft        = parameter.IsLeft;
            object value         = ExpressionTool.GetMemberValue(expression.Member, expression);
            var    baseParameter = parameter.BaseParameter;
            var    isSetTempData = baseParameter.CommonTempData.HasValue() && baseParameter.CommonTempData.Equals(CommonTempDataType.Result);

            switch (parameter.Context.ResolveType)
            {
            case ResolveExpressType.Update:
            case ResolveExpressType.SelectSingle:
            case ResolveExpressType.SelectMultiple:
                if (value != null && value.GetType().IsEnum())
                {
                    value = Convert.ToInt64(value);
                }
                parameter.BaseParameter.CommonTempData = value;
                break;

            case ResolveExpressType.WhereSingle:
            case ResolveExpressType.WhereMultiple:
                if (isSetTempData)
                {
                    baseParameter.CommonTempData = value;
                }
                else
                {
                    AppendValue(parameter, isLeft, value);
                }
                break;

            case ResolveExpressType.FieldSingle:
            case ResolveExpressType.FieldMultiple:
                break;
            }
        }
Exemplo n.º 12
0
        protected void SqlFuncMethod(ExpressionParameter parameter, MethodCallExpression express, bool?isLeft)
        {
            if (!CheckMethod(express))
            {
                CusMethod(parameter, express, isLeft);
            }
            else
            {
                var    method = express.Method;
                string name   = method.Name;
                var    args   = express.Arguments.Cast <Expression>().ToList();
                MethodCallExpressionModel model = new MethodCallExpressionModel();
                model.Args = new List <MethodCallExpressionArgs>();
                switch (this.Context.ResolveType)
                {
                case ResolveExpressType.WhereSingle:
                case ResolveExpressType.WhereMultiple:
                    Check.Exception(name == "GetSelfAndAutoFill", "SqlFunc.GetSelfAndAutoFill can only be used in Select.");
                    Where(parameter, isLeft, name, args, model);
                    break;

                case ResolveExpressType.SelectSingle:
                case ResolveExpressType.SelectMultiple:
                case ResolveExpressType.Update:
                    Select(parameter, isLeft, name, args, model);
                    break;

                case ResolveExpressType.FieldSingle:
                case ResolveExpressType.FieldMultiple:
                    Field(parameter, isLeft, name, args, model);
                    break;

                default:
                    break;
                }
            }
        }
Exemplo n.º 13
0
        private void AppendModelByIIFMember(ExpressionParameter parameter, MethodCallExpressionModel model, Expression item)
        {
            parameter.CommonTempData = CommonTempDataType.Result;
            base.Expression          = item;
            base.Start();
            var methodCallExpressionArgs = new MethodCallExpressionArgs()
            {
                IsMember   = parameter.ChildExpression is MemberExpression,
                MemberName = parameter.CommonTempData
            };

            if (methodCallExpressionArgs.IsMember && parameter.ChildExpression != null && parameter.ChildExpression.ToString() == "DateTime.Now")
            {
                methodCallExpressionArgs.IsMember = false;
            }
            var value = methodCallExpressionArgs.MemberName;

            if (methodCallExpressionArgs.IsMember)
            {
                var childExpression = parameter.ChildExpression as MemberExpression;
                if (childExpression.Expression != null && childExpression.Expression is ConstantExpression)
                {
                    methodCallExpressionArgs.IsMember = false;
                }
            }
            if (methodCallExpressionArgs.IsMember == false)
            {
                var parameterName = this.Context.SqlParameterKeyWord + ExpressionConst.MethodConst + this.Context.ParameterIndex;
                this.Context.ParameterIndex++;
                methodCallExpressionArgs.MemberName  = parameterName;
                methodCallExpressionArgs.MemberValue = value;
                this.Context.Parameters.Add(new AgileParameter(parameterName, value));
            }
            model.Args.Add(methodCallExpressionArgs);
            parameter.ChildExpression = null;
        }
        private void ResolveDateValue(ExpressionParameter parameter, bool?isLeft, MemberExpression expression)
        {
            var name = expression.Member.Name;
            var oldCommonTempDate = parameter.CommonTempData;

            parameter.CommonTempData = CommonTempDataType.Result;
            this.Expression          = expression.Expression;
            var isConst = this.Expression is ConstantExpression;

            if (this.Expression.Type == UtilConstants.DateType && this.Expression.ToString() == "DateTime.Now")
            {
                this.Expression = expression;
                var parameterName = base.AppendParameter(ExpressionTool.GetMemberValue(expression.Member, expression));
                base.AppendMember(parameter, isLeft, parameterName);
            }
            else
            {
                this.Start();
                var result = this.Context.DbMehtods.DateValue(new MethodCallExpressionModel()
                {
                    Args = new List <MethodCallExpressionArgs>()
                    {
                        new MethodCallExpressionArgs()
                        {
                            IsMember = !isConst, MemberName = parameter.CommonTempData, MemberValue = null
                        },
                        new MethodCallExpressionArgs()
                        {
                            IsMember = true, MemberName = name, MemberValue = name
                        }
                    }
                });
                base.AppendMember(parameter, isLeft, result);
            }
            parameter.CommonTempData = oldCommonTempDate;
        }
        private void ResolveHasValue(ExpressionParameter parameter, MemberExpression expression)
        {
            parameter.CommonTempData = CommonTempDataType.Result;
            this.Expression          = expression.Expression;
            this.Start();
            var methodParamter = new MethodCallExpressionArgs()
            {
                IsMember = true, MemberName = parameter.CommonTempData, MemberValue = null
            };

            if (expression.Expression?.Type != null)
            {
                methodParamter.Type = UtilMethods.GetUnderType(expression.Expression?.Type);
            }
            var result = this.Context.DbMehtods.HasValue(new MethodCallExpressionModel()
            {
                Args = new List <MethodCallExpressionArgs>()
                {
                    methodParamter
                }
            });

            if (parameter.BaseExpression != null && ExpressionTool.IsLogicOperator(parameter.BaseExpression) && parameter.IsLeft == true)
            {
                if (base.Context.Result.Contains(ExpressionConst.FormatSymbol))
                {
                    base.Context.Result.Replace(ExpressionConst.FormatSymbol, "");
                }
                this.Context.Result.Append(result + " " + ExpressionTool.GetOperator(parameter.BaseExpression.NodeType) + " ");
            }
            else
            {
                this.Context.Result.Append(result);
            }
            parameter.CommonTempData = null;
        }
Exemplo n.º 16
0
        private void Update(MemberInitExpression expression, ExpressionParameter parameter)
        {
            int i = 0;

            foreach (MemberBinding binding in expression.Bindings)
            {
                ++i;
                if (binding.BindingType != MemberBindingType.Assignment)
                {
                    throw new NotSupportedException();
                }
                MemberAssignment memberAssignment = (MemberAssignment)binding;
                var type       = expression.Type;
                var memberName = this.Context.GetDbColumnName(type.Name, memberAssignment.Member.Name);
                var item       = memberAssignment.Expression;
                if ((item is MemberExpression) && ((MemberExpression)item).Expression == null)
                {
                    var    paramterValue = ExpressionTool.DynamicInvoke(item);
                    string parameterName = AppendParameter(paramterValue);
                    this.Context.Result.Append(base.Context.GetEqString(memberName, parameterName));
                }
                else if (IsNotMember(item))
                {
                    if (base.Context.Result.IsLockCurrentParameter == false)
                    {
                        base.Context.Result.CurrentParameter       = parameter;
                        base.Context.Result.IsLockCurrentParameter = true;
                        parameter.IsAppendTempDate();
                        base.Expression = item;
                        base.Expression = (item as UnaryExpression).Operand;
                        base.Start();
                        parameter.IsAppendResult();
                        var result = this.Context.DbMehtods.IIF(new MethodCallExpressionModel()
                        {
                            Args = new List <MethodCallExpressionArgs>()
                            {
                                new MethodCallExpressionArgs()
                                {
                                    IsMember = true, MemberName = parameter.CommonTempData.ObjToString() + "=1"
                                },
                                new MethodCallExpressionArgs()
                                {
                                    IsMember = true, MemberName = AppendParameter(0)
                                },
                                new MethodCallExpressionArgs()
                                {
                                    IsMember = true, MemberName = AppendParameter(1)
                                }
                            }
                        });
                        parameter.Context.Result.Append(base.Context.GetEqString(memberName, result));
                        base.Context.Result.CurrentParameter = null;
                    }
                }
                else if (IsNotParameter(item))
                {
                    try
                    {
                        parameter.Context.Result.Append(base.Context.GetEqString(memberName, AppendParameter(ExpressionTool.DynamicInvoke(item).ObjToBool())));
                    }
                    catch
                    {
                        throw new NotSupportedException(item.ToString());
                    }
                }
                else if (IsMethod(item))
                {
                    if (item is UnaryExpression)
                    {
                        item = (item as UnaryExpression).Operand;
                    }
                    var callMethod = item as MethodCallExpression;
                    if (MethodTimeMapping.Any(it => it.Key == callMethod.Method.Name) || MethodMapping.Any(it => it.Key == callMethod.Method.Name) || IsExtMethod(callMethod.Method.Name) || IsSubMethod(callMethod) || callMethod.Method.DeclaringType.FullName.StartsWith(UtilConstants.AssemblyName + UtilConstants.Dot))
                    {
                        MethodCall(parameter, memberName, item);
                    }
                    else
                    {
                        var    paramterValue = ExpressionTool.DynamicInvoke(item);
                        string parameterName = AppendParameter(paramterValue);
                        this.Context.Result.Append(base.Context.GetEqString(memberName, parameterName));
                    }
                }
                else if (IsConst(item) && IsConvert(item) && UtilMethods.IsNullable(item.Type) && UtilMethods.GetUnderType(item.Type) == UtilConstants.BoolType)
                {
                    item = (item as UnaryExpression).Operand;
                    parameter.Context.Result.Append(base.Context.GetEqString(memberName, GetNewExpressionValue(item)));
                }
                else if (IsConst(item))
                {
                    base.Expression = item;
                    base.Start();
                    string parameterName = this.Context.SqlParameterKeyWord + ExpressionConst.Const + this.Context.ParameterIndex;
                    parameter.Context.Result.Append(base.Context.GetEqString(memberName, parameterName));
                    this.Context.Parameters.Add(new AgileParameter(parameterName, parameter.CommonTempData));
                    this.Context.ParameterIndex++;
                }
                else if (item is MemberExpression)
                {
                    if (base.Context.Result.IsLockCurrentParameter == false)
                    {
                        base.Context.Result.CurrentParameter       = parameter;
                        base.Context.Result.IsLockCurrentParameter = true;
                        parameter.IsAppendTempDate();
                        base.Expression = item;
                        base.Start();
                        parameter.IsAppendResult();
                        parameter.Context.Result.Append(base.Context.GetEqString(memberName, parameter.CommonTempData.ObjToString()));
                        base.Context.Result.CurrentParameter = null;
                    }
                }
                else if (item is BinaryExpression)
                {
                    var result = GetNewExpressionValue(item);
                    this.Context.Result.Append(base.Context.GetEqString(memberName, result));
                }
                else if (item is MemberInitExpression)
                {
                    try
                    {
                        var value         = ExpressionTool.DynamicInvoke(item);
                        var parameterName = AppendParameter(value);
                        parameter.Context.Result.Append(base.Context.GetEqString(memberName, parameterName));
                    }
                    catch (Exception ex)
                    {
                        throw new NotSupportedException("Not Supported " + item.ToString() + " " + ex.Message);
                    }
                }
                else if (item is NewExpression)
                {
                    try
                    {
                        var value         = ExpressionTool.DynamicInvoke(item);
                        var parameterName = AppendParameter(value);
                        parameter.Context.Result.Append(base.Context.GetEqString(memberName, parameterName));
                    }
                    catch (Exception ex)
                    {
                        throw new NotSupportedException("Not Supported " + item.ToString() + " " + ex.Message);
                    }
                }
            }
        }
Exemplo n.º 17
0
        public MethodCallExpressionResolve(ExpressionParameter parameter) : base(parameter)
        {
            contextIndex = this.Context.Index;
            var express = base.Expression as MethodCallExpression;

            if (express == null)
            {
                return;
            }
            var    isLeft              = parameter.IsLeft;
            string methodName          = express.Method.Name;
            var    isValidNativeMethod = IsValidNativeMethod(express, methodName);
            List <MethodCallExpressionArgs> appendArgs = null;

            if (MethodTimeMapping.ContainsKey(methodName))
            {
                appendArgs = new List <MethodCallExpressionArgs>();
                var    dateType     = MethodTimeMapping[methodName];
                string paramterName = this.Context.SqlParameterKeyWord + ExpressionConst.Const + this.Context.ParameterIndex;
                appendArgs.Add(new MethodCallExpressionArgs()
                {
                    IsMember = false, MemberName = paramterName, MemberValue = dateType
                });
                this.Context.Parameters.Add(new AgileParameter(paramterName, dateType.ToString()));
                this.Context.ParameterIndex++;
                methodName          = "DateAdd";
                isValidNativeMethod = true;
            }
            else if (methodName == "get_Item")
            {
                string paramterName = this.Context.SqlParameterKeyWord + ExpressionConst.Const + this.Context.ParameterIndex;
                this.Context.Parameters.Add(new AgileParameter(paramterName, ExpressionTool.DynamicInvoke(express)));
                this.Context.Result.Append(string.Format(" {0} ", paramterName));
                this.Context.ParameterIndex++;
                return;
            }
            else if (methodName == "NewGuid")
            {
                this.Context.Result.Append(this.Context.DbMehtods.GuidNew());
                return;
            }
            else if (IsSubMethod(express, methodName))
            {
                //Check.Exception(!(parameter.BaseExpression is BinaryExpression), "Current expressions are not supported");
                SubResolve subResolve = new SubResolve(express, this.Context, parameter.OppsiteExpression);
                var        appendSql  = subResolve.GetSql();
                if (this.Context.ResolveType.IsIn(ResolveExpressType.SelectMultiple, ResolveExpressType.SelectSingle) || (parameter.BaseParameter != null && parameter.BaseParameter.CommonTempData != null && parameter.BaseParameter.CommonTempData.Equals(CommonTempDataType.Result)))
                {
                    parameter.BaseParameter.CommonTempData = appendSql;
                }
                else
                {
                    base.AppendValue(parameter, isLeft, appendSql);
                }
                return;
            }
            else if (IsIfElse(express, methodName))
            {
                CaseWhenResolve caseResole = new CaseWhenResolve(express, this.Context, parameter.OppsiteExpression);
                var             appendSql  = caseResole.GetSql();
                var             isRoot     = contextIndex == 2 && parameter.BaseExpression == null;
                if (isRoot || (parameter.BaseExpression != null && ExpressionTool.IsLogicOperator(parameter.BaseExpression)))
                {
                    appendSql = appendSql + "=1 ";
                }
                if (this.Context.ResolveType.IsIn(ResolveExpressType.SelectMultiple, ResolveExpressType.SelectSingle, ResolveExpressType.Update))
                {
                    parameter.BaseParameter.CommonTempData = appendSql;
                }
                else
                {
                    base.AppendValue(parameter, isLeft, appendSql);
                }
                return;
            }
            if (IsContainsArray(express, methodName, isValidNativeMethod))
            {
                methodName          = "ContainsArray";
                isValidNativeMethod = true;
            }
            if (isValidNativeMethod)
            {
                NativeExtensionMethod(parameter, express, isLeft, MethodMapping[methodName], appendArgs);
            }
            else
            {
                SqlFuncMethod(parameter, express, isLeft);
            }
        }
        public ConstantExpressionResolve(ExpressionParameter parameter) : base(parameter)
        {
            var    expression    = base.Expression as ConstantExpression;
            var    isLeft        = parameter.IsLeft;
            object value         = ExpressionTool.GetValue(expression.Value);
            var    baseParameter = parameter.BaseParameter;

            baseParameter.ChildExpression = expression;
            var isSetTempData = baseParameter.CommonTempData.HasValue() && baseParameter.CommonTempData.Equals(CommonTempDataType.Result);

            switch (parameter.Context.ResolveType)
            {
            case ResolveExpressType.SelectSingle:
            case ResolveExpressType.Update:
            case ResolveExpressType.SelectMultiple:
                baseParameter.CommonTempData = value;
                break;

            case ResolveExpressType.WhereSingle:
            case ResolveExpressType.WhereMultiple:
                if (isSetTempData)
                {
                    baseParameter.CommonTempData = value;
                }
                else
                {
                    var parentIsBinary = parameter.BaseParameter.CurrentExpression is BinaryExpression;
                    var parentIsRoot   = parameter.BaseParameter.CurrentExpression is LambdaExpression;
                    var isBool         = value != null && value.GetType() == UtilConstants.BoolType;
                    if (parentIsRoot && isBool)
                    {
                        this.Context.Result.Append(value.ObjToBool() ? this.Context.DbMehtods.True() : this.Context.DbMehtods.False());
                        break;
                    }
                    if (parentIsBinary && isBool)
                    {
                        var isLogicOperator =
                            parameter.BaseExpression.NodeType == ExpressionType.And ||
                            parameter.BaseExpression.NodeType == ExpressionType.AndAlso ||
                            parameter.BaseExpression.NodeType == ExpressionType.Or ||
                            parameter.BaseExpression.NodeType == ExpressionType.OrElse;
                        if (isLogicOperator)
                        {
                            AppendMember(parameter, isLeft, (value.ObjToBool() ? this.Context.DbMehtods.True() : this.Context.DbMehtods.False()));
                            break;
                        }
                    }
                    if (value == null && parentIsBinary)
                    {
                        parameter.BaseParameter.ValueIsNull = true;
                        value = this.Context.DbMehtods.Null();
                    }
                    AppendValue(parameter, isLeft, value);
                }
                break;

            case ResolveExpressType.FieldSingle:
            case ResolveExpressType.FieldMultiple:
            default:
                break;
            }
        }
Exemplo n.º 19
0
        public UnaryExpressionResolve(ExpressionParameter parameter) : base(parameter)
        {
            var oldExpression = base.Expression;
            var expression    = base.Expression as UnaryExpression;
            var baseParameter = parameter.BaseParameter;

            switch (this.Context.ResolveType)
            {
            case ResolveExpressType.WhereSingle:
            case ResolveExpressType.WhereMultiple:
            case ResolveExpressType.FieldSingle:
            case ResolveExpressType.FieldMultiple:
            case ResolveExpressType.SelectSingle:
            case ResolveExpressType.SelectMultiple:
            case ResolveExpressType.ArraySingle:
            case ResolveExpressType.ArrayMultiple:
            case ResolveExpressType.Update:
                var nodeType = expression.NodeType;
                base.Expression = expression.Operand;
                var isMember     = expression.Operand is MemberExpression;
                var isConst      = expression.Operand is ConstantExpression;
                var offsetIsNull = (parameter.OppsiteExpression is ConstantExpression) &&
                                   (parameter.OppsiteExpression as ConstantExpression).Value == null &&
                                   ExpressionTool.IsComparisonOperator(expression.Operand);
                if (isMember && offsetIsNull)
                {
                    Append(parameter, nodeType);
                }
                else if (baseParameter.CurrentExpression is NewArrayExpression)
                {
                    Result(parameter, nodeType);
                }
                else if (baseParameter.OperatorValue == "=" && IsNotMember(oldExpression))
                {
                    AppendNotMember(parameter, nodeType);
                }
                else if (baseParameter.OperatorValue == "=" && IsNotParameter(oldExpression))
                {
                    AppendNotParameter(parameter, nodeType);
                }
                else if (base.Expression is BinaryExpression || parameter.BaseExpression is BinaryExpression || baseParameter.CommonTempData.ObjToString() == CommonTempDataType.Append.ToString())
                {
                    Append(parameter, nodeType);
                }
                else if (isMember)
                {
                    MemberLogic(parameter, baseParameter, nodeType);
                }
                else if (isConst)
                {
                    Result(parameter, nodeType);
                }
                else
                {
                    Append(parameter, nodeType);
                }
                break;

            default:
                break;
            }
        }
Exemplo n.º 20
0
        public NewExpressionResolve(ExpressionParameter parameter) : base(parameter)
        {
            var expression = base.Expression as NewExpression;

            if (expression.Type.IsIn(UtilConstants.DateType, UtilConstants.GuidType))
            {
                NewValueType(parameter, expression);
                return;
            }
            switch (parameter.Context.ResolveType)
            {
            case ResolveExpressType.WhereSingle:
                Check.ThrowNotSupportedException(expression.ToString());
                break;

            case ResolveExpressType.WhereMultiple:
                Check.ThrowNotSupportedException(expression.ToString());
                break;

            case ResolveExpressType.SelectSingle:
                Check.Exception(expression.Type == UtilConstants.DateType, "ThrowNotSupportedException {0} ", expression.ToString());
                Select(expression, parameter, true);
                break;

            case ResolveExpressType.SelectMultiple:
                Check.Exception(expression.Type == UtilConstants.DateType, "ThrowNotSupportedException {0} ", expression.ToString());
                Select(expression, parameter, false);
                break;

            case ResolveExpressType.FieldSingle:
                Check.ThrowNotSupportedException(expression.ToString());
                break;

            case ResolveExpressType.FieldMultiple:
            case ResolveExpressType.ArrayMultiple:
            case ResolveExpressType.ArraySingle:
                foreach (var item in expression.Arguments)
                {
                    base.Expression = item;
                    base.Start();
                }
                break;

            case ResolveExpressType.Join:
                base.Context.ResolveType = ResolveExpressType.WhereMultiple;
                int i = 0;
                foreach (var item in expression.Arguments)
                {
                    if (item.Type != typeof(JoinType))
                    {
                        base.Expression = item;
                        base.Start();
                    }
                    if (item.Type == typeof(JoinType))
                    {
                        if (i > 0)
                        {
                            base.Context.Result.Append("," + item.ToString() + ",");
                        }
                        else
                        {
                            base.Context.Result.Append(item.ToString() + ",");
                        }
                        ++i;
                    }
                }
                break;

            default:
                break;
            }
        }
Exemplo n.º 21
0
 protected void AppendValue(ExpressionParameter parameter, bool?isLeft, object value)
 {
     if (parameter.BaseExpression is BinaryExpression || parameter.BaseExpression == null)
     {
         var oppoSiteExpression = isLeft == true ? parameter.BaseParameter.RightExpression : parameter.BaseParameter.LeftExpression;
         if (parameter.CurrentExpression is MethodCallExpression || parameter.CurrentExpression is ConditionalExpression || parameter.CurrentExpression.NodeType == ExpressionType.Coalesce)
         {
             var appendValue = value;
             if (this.Context.Result.Contains(ExpressionConst.FormatSymbol))
             {
                 this.Context.Result.Replace(ExpressionConst.FormatSymbol, appendValue.ObjToString());
             }
             else
             {
                 this.Context.Result.Append(appendValue);
             }
             this.AppendOpreator(parameter, isLeft);
         }
         else if (oppoSiteExpression is MemberExpression)
         {
             string appendValue = Context.SqlParameterKeyWord
                                  + ((MemberExpression)oppoSiteExpression).Member.Name
                                  + Context.ParameterIndex;
             if (value.ObjToString() != "NULL" && !parameter.ValueIsNull)
             {
                 this.Context.Parameters.Add(new AgileParameter(appendValue, value));
             }
             else
             {
                 appendValue = value.ObjToString();
             }
             Context.ParameterIndex++;
             appendValue = string.Format(" {0} ", appendValue);
             if (isLeft == true)
             {
                 appendValue += ExpressionConst.ExpressionReplace + parameter.BaseParameter.Index;
             }
             if (this.Context.Result.Contains(ExpressionConst.FormatSymbol))
             {
                 this.Context.Result.Replace(ExpressionConst.FormatSymbol, appendValue);
             }
             else
             {
                 this.Context.Result.Append(appendValue);
             }
         }
         else if ((oppoSiteExpression is UnaryExpression && (oppoSiteExpression as UnaryExpression).Operand is MemberExpression))
         {
             string appendValue = Context.SqlParameterKeyWord
                                  + ((MemberExpression)(oppoSiteExpression as UnaryExpression).Operand).Member.Name
                                  + Context.ParameterIndex;
             if (value.ObjToString() != "NULL" && !parameter.ValueIsNull)
             {
                 this.Context.Parameters.Add(new AgileParameter(appendValue, value));
             }
             else
             {
                 appendValue = value.ObjToString();
             }
             Context.ParameterIndex++;
             appendValue = string.Format(" {0} ", appendValue);
             if (isLeft == true)
             {
                 appendValue += ExpressionConst.ExpressionReplace + parameter.BaseParameter.Index;
             }
             if (this.Context.Result.Contains(ExpressionConst.FormatSymbol))
             {
                 this.Context.Result.Replace(ExpressionConst.FormatSymbol, appendValue);
             }
             else
             {
                 this.Context.Result.Append(appendValue);
             }
         }
         else
         {
             var appendValue = this.Context.SqlParameterKeyWord + ExpressionConst.Const + Context.ParameterIndex;
             Context.ParameterIndex++;
             if (value != null && value.GetType().IsEnum())
             {
                 value = Convert.ToInt64(value);
             }
             this.Context.Parameters.Add(new AgileParameter(appendValue, value));
             appendValue = string.Format(" {0} ", appendValue);
             if (isLeft == true)
             {
                 appendValue += ExpressionConst.ExpressionReplace + parameter.BaseParameter.Index;
             }
             if (this.Context.Result.Contains(ExpressionConst.FormatSymbol))
             {
                 this.Context.Result.Replace(ExpressionConst.FormatSymbol, appendValue);
             }
             else
             {
                 this.Context.Result.Append(appendValue);
             }
         }
     }
 }
Exemplo n.º 22
0
 protected void ResolveNewExpressions(ExpressionParameter parameter, Expression item, string asName)
 {
     if (item is ConstantExpression)
     {
         this.Expression = item;
         this.Start();
         string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
         this.Context.ParameterIndex++;
         parameter.Context.Result.Append(this.Context.GetAsString(asName, parameterName));
         this.Context.Parameters.Add(new AgileParameter(parameterName, parameter.CommonTempData));
     }
     else if ((item is MemberExpression) && ((MemberExpression)item).Expression == null)
     {
         var    paramterValue = ExpressionTool.GetPropertyValue(item as MemberExpression);
         string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
         this.Context.ParameterIndex++;
         parameter.Context.Result.Append(this.Context.GetAsString(asName, parameterName));
         this.Context.Parameters.Add(new AgileParameter(parameterName, paramterValue));
     }
     else if ((item is MemberExpression) && ((MemberExpression)item).Expression.NodeType == ExpressionType.Constant)
     {
         this.Expression = item;
         this.Start();
         string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
         this.Context.ParameterIndex++;
         parameter.Context.Result.Append(this.Context.GetAsString(asName, parameterName));
         this.Context.Parameters.Add(new AgileParameter(parameterName, parameter.CommonTempData));
     }
     else if (item is MemberExpression)
     {
         if (this.Context.Result.IsLockCurrentParameter == false)
         {
             this.Context.Result.CurrentParameter       = parameter;
             this.Context.Result.IsLockCurrentParameter = true;
             parameter.IsAppendTempDate();
             this.Expression = item;
             this.Start();
             parameter.IsAppendResult();
             this.Context.Result.Append(this.Context.GetAsString(asName, parameter.CommonTempData.ObjToString()));
             this.Context.Result.CurrentParameter = null;
         }
     }
     else if (item is UnaryExpression && ((UnaryExpression)item).Operand is MemberExpression)
     {
         if (this.Context.Result.IsLockCurrentParameter == false)
         {
             var expression    = ((UnaryExpression)item).Operand as MemberExpression;
             var isDateTimeNow = ((UnaryExpression)item).Operand.ToString() == "DateTime.Now";
             if (expression.Expression == null && !isDateTimeNow)
             {
                 this.Context.Result.CurrentParameter       = parameter;
                 this.Context.Result.IsLockCurrentParameter = true;
                 parameter.IsAppendTempDate();
                 this.Expression = item;
                 this.Start();
                 parameter.IsAppendResult();
                 this.Context.Result.Append(this.Context.GetAsString(asName, parameter.CommonTempData.ObjToString()));
                 this.Context.Result.CurrentParameter = null;
             }
             else if (expression.Expression is ConstantExpression || isDateTimeNow)
             {
                 string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
                 this.Context.ParameterIndex++;
                 parameter.Context.Result.Append(this.Context.GetAsString(asName, parameterName));
                 this.Context.Parameters.Add(new AgileParameter(parameterName, ExpressionTool.GetMemberValue(expression.Member, expression)));
             }
             else
             {
                 this.Context.Result.CurrentParameter       = parameter;
                 this.Context.Result.IsLockCurrentParameter = true;
                 parameter.IsAppendTempDate();
                 this.Expression = item;
                 this.Start();
                 parameter.IsAppendResult();
                 this.Context.Result.Append(this.Context.GetAsString(asName, parameter.CommonTempData.ObjToString()));
                 this.Context.Result.CurrentParameter = null;
             }
         }
     }
     else if (item is UnaryExpression && ((UnaryExpression)item).Operand is ConstantExpression)
     {
         if (this.Context.Result.IsLockCurrentParameter == false)
         {
             this.Expression = ((UnaryExpression)item).Operand;
             this.Start();
             string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
             this.Context.ParameterIndex++;
             parameter.Context.Result.Append(this.Context.GetAsString(asName, parameterName));
             this.Context.Parameters.Add(new AgileParameter(parameterName, parameter.CommonTempData));
         }
     }
     else if (item is BinaryExpression)
     {
         if (this.Context.Result.IsLockCurrentParameter == false)
         {
             var newContext         = this.Context.GetCopyContextWithMapping();
             var resolveExpressType = this.Context.IsSingle ? ResolveExpressType.WhereSingle : ResolveExpressType.WhereMultiple;
             newContext.Resolve(item, resolveExpressType);
             this.Context.Index          = newContext.Index;
             this.Context.ParameterIndex = newContext.ParameterIndex;
             if (newContext.Parameters.HasValue())
             {
                 this.Context.Parameters.AddRange(newContext.Parameters);
             }
             this.Context.Result.Append(this.Context.GetAsString(asName, newContext.Result.GetString()));
             this.Context.Result.CurrentParameter = null;
             if (this.Context.SingleTableNameSubqueryShortName.IsNullOrEmpty() && newContext.SingleTableNameSubqueryShortName.HasValue())
             {
                 this.Context.SingleTableNameSubqueryShortName = newContext.SingleTableNameSubqueryShortName;
             }
         }
     }
     else if (item.Type.IsClass())
     {
         this.Expression = item;
         this.Start();
         var shortName      = parameter.CommonTempData;
         var listProperties = item.Type.GetProperties().Cast <PropertyInfo>().ToList();
         foreach (var property in listProperties)
         {
             var hasIgnore = this.Context.IgnoreComumnList != null && this.Context.IgnoreComumnList.Any(it => it.EntityName.Equals(item.Type.Name, StringComparison.CurrentCultureIgnoreCase) && it.PropertyName.Equals(property.Name, StringComparison.CurrentCultureIgnoreCase));
             if (hasIgnore)
             {
                 continue;
             }
             if (property.PropertyType.IsClass())
             {
             }
             else
             {
                 var propertyName = property.Name;
                 var dbColumnName = propertyName;
                 var mappingInfo  = this.Context.MappingColumns.FirstOrDefault(it => it.EntityName == item.Type.Name && it.PropertyName.Equals(propertyName, StringComparison.CurrentCultureIgnoreCase));
                 if (mappingInfo.HasValue())
                 {
                     dbColumnName = mappingInfo.DbColumnName;
                 }
                 asName = this.Context.GetTranslationText(item.Type.Name + "." + propertyName);
                 if (Context.IsJoin)
                 {
                     this.Context.Result.Append(Context.GetAsString(asName, dbColumnName, shortName.ObjToString()));
                 }
                 else
                 {
                     this.Context.Result.Append(Context.GetAsString(asName, dbColumnName));
                 }
             }
         }
     }
     else if (item.Type == UtilConstants.BoolType && item is MethodCallExpression && (item as MethodCallExpression).Method.Name == "Any" && IsSubMethod(item as MethodCallExpression))
     {
         this.Expression = item;
         this.Start();
         var sql = this.Context.DbMehtods.IIF(new MethodCallExpressionModel()
         {
             Args = new List <MethodCallExpressionArgs>()
             {
                 new MethodCallExpressionArgs()
                 {
                     IsMember   = true,
                     MemberName = parameter.CommonTempData.ObjToString()
                 },
                 new MethodCallExpressionArgs()
                 {
                     IsMember   = true,
                     MemberName = 1
                 },
                 new MethodCallExpressionArgs()
                 {
                     IsMember   = true,
                     MemberName = 0
                 }
             }
         });
         parameter.Context.Result.Append(this.Context.GetAsString(asName, sql));
     }
     else if (item is MethodCallExpression || item is UnaryExpression || item is ConditionalExpression || item.NodeType == ExpressionType.Coalesce)
     {
         this.Expression = item;
         this.Start();
         parameter.Context.Result.Append(this.Context.GetAsString(asName, parameter.CommonTempData.ObjToString()));
     }
     else
     {
         Check.ThrowNotSupportedException(item.GetType().Name);
     }
 }
Exemplo n.º 23
0
 public BaseResolve(ExpressionParameter parameter)
 {
     this.Expression    = parameter.CurrentExpression;
     this.Context       = parameter.Context;
     this.BaseParameter = parameter;
 }
Exemplo n.º 24
0
 private void AppendModelByIIFBinary(ExpressionParameter parameter, MethodCallExpressionModel model, Expression item)
 {
     Check.Exception(true, "The SqlFunc.IIF(arg1,arg2,arg3) , {0} argument  do not support ", item.ToString());
 }
Exemplo n.º 25
0
        public BaseResolve Start()
        {
            Context.Index++;
            Expression          expression = this.Expression;
            ExpressionParameter parameter  = new ExpressionParameter()
            {
                Context           = this.Context,
                CurrentExpression = expression,
                IsLeft            = this.IsLeft,
                BaseExpression    = this.ExactExpression,
                BaseParameter     = this.BaseParameter,
                Index             = Context.Index
            };

            if (expression is LambdaExpression)
            {
                return(new LambdaExpressionResolve(parameter));
            }
            else if (expression is BinaryExpression && expression.NodeType == ExpressionType.Coalesce)
            {
                return(new CoalesceResolveItems(parameter));
            }
            else if (expression is BinaryExpression)
            {
                return(new BinaryExpressionResolve(parameter));
            }
            else if (expression is BlockExpression)
            {
                Check.ThrowNotSupportedException("BlockExpression");
            }
            else if (expression is ConditionalExpression)
            {
                return(new ConditionalExpressionResolve(parameter));
            }
            else if (expression is MethodCallExpression)
            {
                return(new MethodCallExpressionResolve(parameter));
            }
            else if (expression is MemberExpression && ((MemberExpression)expression).Expression == null)
            {
                return(new MemberNoExpressionResolve(parameter));
            }
            else if (expression is MemberExpression && ((MemberExpression)expression).Expression.NodeType == ExpressionType.Constant)
            {
                return(new MemberConstExpressionResolve(parameter));
            }
            else if (expression is MemberExpression && ((MemberExpression)expression).Expression.NodeType == ExpressionType.New)
            {
                return(new MemberNewExpressionResolve(parameter));
            }
            else if (expression is ConstantExpression)
            {
                return(new ConstantExpressionResolve(parameter));
            }
            else if (expression is MemberExpression)
            {
                return(new MemberExpressionResolve(parameter));
            }
            else if (expression is UnaryExpression)
            {
                return(new UnaryExpressionResolve(parameter));
            }
            else if (expression is MemberInitExpression)
            {
                return(new MemberInitExpressionResolve(parameter));
            }
            else if (expression is NewExpression)
            {
                return(new NewExpressionResolve(parameter));
            }
            else if (expression is NewArrayExpression)
            {
                return(new NewArrayExpessionResolve(parameter));
            }
            else if (expression is ParameterExpression)
            {
                return(new TypeParameterExpressionReolve(parameter));
            }
            else if (expression != null && expression.NodeType.IsIn(ExpressionType.NewArrayBounds))
            {
                Check.ThrowNotSupportedException("ExpressionType.NewArrayBounds");
            }
            return(null);
        }
Exemplo n.º 26
0
        private void AppendModel(ExpressionParameter parameter, MethodCallExpressionModel model, Expression item)
        {
            parameter.CommonTempData = CommonTempDataType.Result;
            base.Expression          = item;
            if (item.Type == UtilConstants.DateType && parameter.CommonTempData.ObjToString() == CommonTempDataType.Result.ToString() && item.ToString() == "DateTime.Now.Date")
            {
                parameter.CommonTempData = DateTime.Now.Date;
            }
            else if (IsDateDate(item))
            {
                parameter.CommonTempData = GetNewExpressionValue(item);
            }
            else if (IsDateValue(item))
            {
                parameter.CommonTempData = GetNewExpressionValue(item);
            }
            else if (model.Name == "ToString" && item is ConstantExpression && (item as ConstantExpression).Type.IsEnum())
            {
                parameter.CommonTempData = item.ToString();
            }
            else
            {
                base.Start();
            }
            var methodCallExpressionArgs = new MethodCallExpressionArgs()
            {
                IsMember   = parameter.ChildExpression is MemberExpression && !ExpressionTool.IsConstExpression(parameter.ChildExpression as MemberExpression),
                MemberName = parameter.CommonTempData
            };

            if (methodCallExpressionArgs.IsMember && parameter.ChildExpression != null && parameter.ChildExpression.ToString() == "DateTime.Now")
            {
                methodCallExpressionArgs.IsMember = false;
            }
            var value = methodCallExpressionArgs.MemberName;

            if (methodCallExpressionArgs.IsMember)
            {
                var childExpression = parameter.ChildExpression as MemberExpression;
                if (childExpression.Expression != null && childExpression.Expression is ConstantExpression)
                {
                    methodCallExpressionArgs.IsMember = false;
                }
            }
            if (IsDateDate(item) || IsDateValue(item))
            {
                methodCallExpressionArgs.IsMember = true;
            }
            if (methodCallExpressionArgs.IsMember == false && (item is MethodCallExpression && item.ToString() == "GetDate()") || (item is UnaryExpression && ((UnaryExpression)item).Operand.ToString() == "GetDate()"))
            {
                var parameterName = this.Context.SqlParameterKeyWord + ExpressionConst.MethodConst + this.Context.ParameterIndex;
                this.Context.ParameterIndex++;
                methodCallExpressionArgs.MemberName  = value;
                methodCallExpressionArgs.MemberValue = null;
            }
            else if (methodCallExpressionArgs.IsMember == false)
            {
                var parameterName = this.Context.SqlParameterKeyWord + ExpressionConst.MethodConst + this.Context.ParameterIndex;
                this.Context.ParameterIndex++;
                methodCallExpressionArgs.MemberName  = parameterName;
                methodCallExpressionArgs.MemberValue = value;
                this.Context.Parameters.Add(new AgileParameter(parameterName, value));
            }
            model.Args.Add(methodCallExpressionArgs);
            parameter.ChildExpression = null;
        }
Exemplo n.º 27
0
        public BinaryExpressionResolve(ExpressionParameter parameter) : base(parameter)
        {
            var expression           = this.Expression as BinaryExpression;
            var operatorValue        = parameter.OperatorValue = ExpressionTool.GetOperator(expression.NodeType);
            var isEqual              = expression.NodeType == ExpressionType.Equal;
            var isComparisonOperator = ExpressionTool.IsComparisonOperator(expression);

            base.ExactExpression = expression;
            var leftExpression  = expression.Left;
            var rightExpression = expression.Right;
            var leftIsBinary    = leftExpression is BinaryExpression;
            var rightBinary     = rightExpression is BinaryExpression;
            var lbrs            = leftIsBinary && !rightBinary;
            var lsrb            = !leftIsBinary && rightBinary;
            var lbrb            = rightBinary && leftIsBinary;
            var lsbs            = !leftIsBinary && !rightBinary;
            var isAppend        = !base.Context.Result.Contains(ExpressionConst.FormatSymbol);

            if (isAppend)
            {
                base.Context.Result.Append(ExpressionConst.LeftParenthesis);
                base.Context.Result.Append(ExpressionConst.FormatSymbol);
            }
            else
            {
                base.Context.Result.Replace(ExpressionConst.FormatSymbol, ExpressionConst.LeftParenthesis + ExpressionConst.FormatSymbol);
            }
            if (leftExpression is UnaryExpression && (leftExpression as UnaryExpression).Operand is UnaryExpression && (leftExpression as UnaryExpression).NodeType == ExpressionType.Convert)
            {
                leftExpression = (leftExpression as UnaryExpression).Operand;
            }
            if (leftExpression is UnaryExpression && (leftExpression as UnaryExpression).Operand.Type == UtilConstants.BoolType && (leftExpression as UnaryExpression).NodeType == ExpressionType.Convert && rightExpression.Type == UtilConstants.BoolTypeNull)
            {
                leftExpression = (leftExpression as UnaryExpression).Operand;
            }
            if (rightExpression is UnaryExpression && (rightExpression as UnaryExpression).Operand.Type == UtilConstants.BoolType && (rightExpression as UnaryExpression).NodeType == ExpressionType.Convert)
            {
                rightExpression = (rightExpression as UnaryExpression).Operand;
            }
            parameter.LeftExpression  = leftExpression;
            parameter.RightExpression = rightExpression;
            base.Expression           = leftExpression;
            base.IsLeft = true;
            base.Start();
            if (leftExpression is UnaryExpression && leftExpression.Type == UtilConstants.BoolType && !this.Context.Result.Contains(ExpressionConst.ExpressionReplace))
            {
                this.Context.Result.AppendFormat(" {0} ", ExpressionTool.GetOperator(expression.NodeType));
            }
            base.IsLeft     = false;
            base.Expression = rightExpression;
            base.Start();
            base.IsLeft = null;
            if (lsbs && parameter.ValueIsNull)
            {
                base.Context.Result.Replace(ExpressionConst.ExpressionReplace + parameter.Index, isEqual ? "IS" : "IS NOT");
                base.Context.Result.Replace(ExpressionConst.ExpressionReplace + (parameter.Index + 1), isEqual ? "IS" : "IS NOT");
            }
            else
            {
                base.Context.Result.Replace(ExpressionConst.ExpressionReplace + parameter.Index, operatorValue);
                base.Context.Result.Replace(ExpressionConst.ExpressionReplace + (parameter.Index + 1), operatorValue);
            }
            base.Context.Result.Append(ExpressionConst.RightParenthesis);
            if (parameter.BaseExpression is BinaryExpression && parameter.IsLeft == true)
            {
                base.Context.Result.Append(" " + ExpressionConst.ExpressionReplace + parameter.BaseParameter.Index + " ");
            }
        }
        public NewArrayExpessionResolve(ExpressionParameter parameter) : base(parameter)
        {
            var expression = (NewArrayExpression)base.Expression;

            switch (base.Context.ResolveType)
            {
            case ResolveExpressType.WhereSingle:
            case ResolveExpressType.WhereMultiple:
            case ResolveExpressType.SelectSingle:
            case ResolveExpressType.SelectMultiple:
            case ResolveExpressType.FieldSingle:
            case ResolveExpressType.FieldMultiple:
                try
                {
                    var value         = ExpressionTool.DynamicInvoke(expression);
                    var isLeft        = parameter.IsLeft;
                    var baseParameter = parameter.BaseParameter;
                    var isSetTempData = baseParameter.CommonTempData.HasValue() && baseParameter.CommonTempData.Equals(CommonTempDataType.Result);
                    if (isSetTempData)
                    {
                        baseParameter.CommonTempData = value;
                    }
                    else
                    {
                        var parentIsBinary = parameter.BaseParameter.CurrentExpression is BinaryExpression;
                        var parentIsRoot   = parameter.BaseParameter.CurrentExpression is LambdaExpression;
                        var isBool         = value != null && value.GetType() == UtilConstants.BoolType;
                        if (parentIsRoot && isBool)
                        {
                            this.Context.Result.Append(value.ObjToBool() ? this.Context.DbMehtods.True() : this.Context.DbMehtods.False());
                            break;
                        }
                        if (parentIsBinary && isBool)
                        {
                            var isLogicOperator =
                                parameter.BaseExpression.NodeType == ExpressionType.And ||
                                parameter.BaseExpression.NodeType == ExpressionType.AndAlso ||
                                parameter.BaseExpression.NodeType == ExpressionType.Or ||
                                parameter.BaseExpression.NodeType == ExpressionType.OrElse;
                            if (isLogicOperator)
                            {
                                AppendMember(parameter, isLeft, (value.ObjToBool() ? this.Context.DbMehtods.True() : this.Context.DbMehtods.False()));
                                break;
                            }
                        }
                        if (value == null && parentIsBinary)
                        {
                            parameter.BaseParameter.ValueIsNull = true;
                            value = this.Context.DbMehtods.Null();
                        }
                        AppendValue(parameter, isLeft, value);
                    }
                }
                catch (Exception)
                {
                    Check.ThrowNotSupportedException("NewArrayExpression");
                }
                break;

            case ResolveExpressType.ArraySingle:
                foreach (var item in expression.Expressions)
                {
                    base.Expression = item;
                    base.Start();
                }
                break;

            case ResolveExpressType.Join:
                base.Context.ResolveType = ResolveExpressType.WhereMultiple;
                int i = 0;
                foreach (var item in expression.Expressions)
                {
                    if (item is UnaryExpression)
                    {
                        base.Expression = item;
                        base.Start();
                        if (parameter.CommonTempData is JoinType)
                        {
                            if (i > 0)
                            {
                                base.Context.Result.Append("," + parameter.CommonTempData.ObjToString().Replace(",", UtilConstants.ReplaceCommaKey) + ",");
                            }
                            else
                            {
                                base.Context.Result.Append(parameter.CommonTempData.ObjToString().Replace(",", UtilConstants.ReplaceCommaKey) + ",");
                            }
                            ++i;
                        }
                    }
                }
                break;

            default:
                break;
            }
        }
Exemplo n.º 29
0
 public BlockExpressionResolve(ExpressionParameter parameter) : base(parameter)
 {
 }