示例#1
0
        protected MethodCallExpressionArgs GetMethodCallArgs(ExpressionParameter parameter, Expression item)
        {
            var newContext = this.Context.GetCopyContext();

            newContext.MappingColumns   = this.Context.MappingColumns;
            newContext.MappingTables    = this.Context.MappingTables;
            newContext.IgnoreComumnList = this.Context.IgnoreComumnList;
            newContext.IsSingle         = this.Context.IsSingle;
            newContext.SqlFuncServices  = this.Context.SqlFuncServices;
            newContext.Resolve(item, this.Context.IsJoin ? ResolveExpressType.WhereMultiple : ResolveExpressType.WhereSingle);
            this.Context.Index          = newContext.Index;
            this.Context.ParameterIndex = newContext.ParameterIndex;
            if (newContext.Parameters.HasValue())
            {
                this.Context.Parameters.AddRange(newContext.Parameters);
            }
            if (newContext.SingleTableNameSubqueryShortName.HasValue())
            {
                this.Context.SingleTableNameSubqueryShortName = newContext.SingleTableNameSubqueryShortName;
            }
            var methodCallExpressionArgs = new MethodCallExpressionArgs()
            {
                IsMember   = true,
                MemberName = newContext.Result.GetResultString()
            };

            return(methodCallExpressionArgs);
        }
        private void ResolveLength(ExpressionParameter parameter, bool?isLeft, MemberExpression expression)
        {
            if (parameter.Context.ResolveType == ResolveExpressType.FieldSingle)
            {
                parameter.Context.ResolveType = ResolveExpressType.WhereSingle;
            }
            if (parameter.Context.ResolveType == ResolveExpressType.FieldMultiple)
            {
                parameter.Context.ResolveType = ResolveExpressType.WhereMultiple;
            }
            var oldCommonTempDate = parameter.CommonTempData;

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

            this.Start();
            var methodParamter = new MethodCallExpressionArgs()
            {
                IsMember = !isConst, MemberName = parameter.CommonTempData, MemberValue = null
            };
            var result = this.Context.DbMehtods.Length(new MethodCallExpressionModel()
            {
                Args = new List <MethodCallExpressionArgs>()
                {
                    methodParamter
                }
            });

            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
            };
            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;
        }
示例#4
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 (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 (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 SugarParameter(parameterName, value));
            }
            model.Args.Add(methodCallExpressionArgs);
            parameter.ChildExpression = null;
        }
示例#5
0
        private void AppendItem(ExpressionParameter parameter, string name, IEnumerable <Expression> args, MethodCallExpressionModel model, Expression item)
        {
            if (ExpressionTool.IsUnConvertExpress(item))
            {
                item = (item as UnaryExpression).Operand;
            }
            var isBinaryExpression = item is BinaryExpression || item is MethodCallExpression;
            var isConst            = item is ConstantExpression;
            var isIIF           = name == "IIF";
            var isIFFBoolMember = isIIF && (item is MemberExpression) && (item as MemberExpression).Type == UtilConstants.BoolType;
            var isIFFUnary      = isIIF && (item is UnaryExpression) && (item as UnaryExpression).Operand.Type == UtilConstants.BoolType;
            var isIFFBoolBinary = isIIF && (item is BinaryExpression) && (item as BinaryExpression).Type == UtilConstants.BoolType;
            var isIFFBoolMethod = isIIF && (item is MethodCallExpression) && (item as MethodCallExpression).Type == UtilConstants.BoolType;
            var isFirst         = item == args.First();

            if (isFirst && isIIF && isConst)
            {
                var value = (item as ConstantExpression).Value.ObjToBool() ? this.Context.DbMehtods.True() : this.Context.DbMehtods.False();
                var methodCallExpressionArgs = new MethodCallExpressionArgs()
                {
                    IsMember    = true,
                    MemberName  = value,
                    MemberValue = value
                };
                model.Args.Add(methodCallExpressionArgs);
            }
            else if (isIFFUnary && !isFirst)
            {
                AppendModelByIIFMember(parameter, model, (item as UnaryExpression).Operand);
            }
            else if (isIFFBoolMember && !isFirst)
            {
                AppendModelByIIFMember(parameter, model, item);
            }
            else if (isIFFBoolBinary && !isFirst)
            {
                AppendModelByIIFBinary(parameter, model, item);
            }
            else if (isIFFBoolMethod && !isFirst)
            {
                AppendModelByIIFMethod(parameter, model, item);
            }
            else if (isBinaryExpression)
            {
                model.Args.Add(GetMethodCallArgs(parameter, item));
            }
            else
            {
                AppendModel(parameter, model, item);
            }
        }
示例#6
0
        protected MethodCallExpressionArgs GetMethodCallArgs(ExpressionParameter parameter, Expression item)
        {
            var newContext = this.Context.GetCopyContext();

            newContext.Resolve(item, this.Context.IsJoin ? ResolveExpressType.WhereMultiple : ResolveExpressType.WhereSingle);
            this.Context.Index          = newContext.Index;
            this.Context.ParameterIndex = newContext.ParameterIndex;
            if (newContext.Parameters.IsValuable())
            {
                this.Context.Parameters.AddRange(newContext.Parameters);
            }
            var methodCallExpressionArgs = new MethodCallExpressionArgs()
            {
                IsMember   = true,
                MemberName = newContext.Result.GetResultString()
            };

            return(methodCallExpressionArgs);
        }
示例#7
0
        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
            };
            var result = this.Context.DbMehtods.HasValue(new MethodCallExpressionModel()
            {
                Args = new List <MethodCallExpressionArgs>()
                {
                    methodParamter
                }
            });

            this.Context.Result.Append(result);
            parameter.CommonTempData = null;
        }
示例#8
0
        private void AppendModel(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 SugarParameter(parameterName, value));
            }
            model.Args.Add(methodCallExpressionArgs);
            parameter.ChildExpression = null;
        }
示例#9
0
        public MemberExpressionResolve(ExpressionParameter parameter) : base(parameter)
        {
            var baseParameter = parameter.BaseParameter;
            var isLeft        = parameter.IsLeft;
            var isSetTempData = baseParameter.CommonTempData.IsValuable() && baseParameter.CommonTempData.Equals(CommonTempDataType.Result);
            var expression    = base.Expression as MemberExpression;
            var isValue       = expression.Member.Name == "Value" && expression.Member.DeclaringType.Name == "Nullable`1";
            var isBool        = expression.Type == PubConst.BoolType;
            var isValueBool   = isValue && isBool && parameter.BaseExpression == null;
            var isLength      = expression.Member.Name == "Length" && (expression.Expression as MemberExpression).Type == PubConst.StringType;
            var isDateValue   = expression.Member.Name.IsIn(Enum.GetNames(typeof(DateType))) && (expression.Expression as MemberExpression).Type == PubConst.DateType;

            if (isLength)
            {
                var oldCommonTempDate = parameter.CommonTempData;
                parameter.CommonTempData = CommonTempDataType.Result;
                this.Expression          = expression.Expression;
                var isConst = this.Expression is ConstantExpression;
                this.Start();
                var methodParamter = new MethodCallExpressionArgs()
                {
                    IsMember = !isConst, MemberName = parameter.CommonTempData, MemberValue = null
                };
                var result = this.Context.DbMehtods.Length(new MethodCallExpressionModel()
                {
                    Args = new List <MethodCallExpressionArgs>()
                    {
                        methodParamter
                    }
                });
                base.AppendMember(parameter, isLeft, result);
                parameter.CommonTempData = oldCommonTempDate;
                return;
            }
            else if (isDateValue)
            {
                var name = expression.Member.Name;
                var oldCommonTempDate = parameter.CommonTempData;
                parameter.CommonTempData = CommonTempDataType.Result;
                this.Expression          = expression.Expression;
                var isConst = this.Expression is ConstantExpression;
                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;
                return;
            }
            else if (isValueBool)
            {
                isValue = false;
            }
            else if (isValue)
            {
                expression = expression.Expression as MemberExpression;
            }
            else if (expression.Expression != null && expression.Expression.NodeType != ExpressionType.Parameter && !isValueBool)
            {
                var value = ExpressionTool.GetMemberValue(expression.Member, expression);
                if (isSetTempData)
                {
                    baseParameter.CommonTempData = value;
                }
                else
                {
                    AppendValue(parameter, isLeft, value);
                }
                return;
            }
            string fieldName = string.Empty;

            baseParameter.ChildExpression = expression;
            switch (parameter.Context.ResolveType)
            {
            case ResolveExpressType.SelectSingle:
                fieldName = GetSingleName(parameter, expression, isLeft);
                if (isSetTempData)
                {
                    baseParameter.CommonTempData = fieldName;
                }
                else
                {
                    base.Context.Result.Append(fieldName);
                }
                break;

            case ResolveExpressType.SelectMultiple:
                fieldName = GetMultipleName(parameter, expression, isLeft);
                if (isSetTempData)
                {
                    baseParameter.CommonTempData = fieldName;
                }
                else
                {
                    base.Context.Result.Append(fieldName);
                }
                break;

            case ResolveExpressType.WhereSingle:
            case ResolveExpressType.WhereMultiple:
                var isSingle = parameter.Context.ResolveType == ResolveExpressType.WhereSingle;
                if (isSetTempData)
                {
                    fieldName = GetName(parameter, expression, null, isSingle);
                    baseParameter.CommonTempData = fieldName;
                }
                else
                {
                    if (isValueBool)
                    {
                        fieldName = GetName(parameter, expression.Expression as MemberExpression, isLeft, isSingle);
                    }
                    else if (ExpressionTool.IsConstExpression(expression))
                    {
                        var value = ExpressionTool.GetMemberValue(expression.Member, expression);
                        base.AppendValue(parameter, isLeft, value);
                        return;
                    }
                    else
                    {
                        fieldName = GetName(parameter, expression, isLeft, isSingle);
                    }
                    if (expression.Type == PubConst.BoolType && baseParameter.OperatorValue.IsNullOrEmpty())
                    {
                        fieldName = "( " + fieldName + "=1 )";
                    }
                    fieldName = AppendMember(parameter, isLeft, fieldName);
                }
                break;

            case ResolveExpressType.FieldSingle:
                fieldName = GetSingleName(parameter, expression, isLeft);
                base.Context.Result.Append(fieldName);
                break;

            case ResolveExpressType.FieldMultiple:
                fieldName = GetMultipleName(parameter, expression, isLeft);
                base.Context.Result.Append(fieldName);
                break;

            case ResolveExpressType.ArrayMultiple:
            case ResolveExpressType.ArraySingle:
                fieldName = GetName(parameter, expression, isLeft, parameter.Context.ResolveType == ResolveExpressType.ArraySingle);
                base.Context.Result.Append(fieldName);
                break;

            default:
                break;
            }
        }
示例#10
0
        public string GeDateFormat(string formatString, string value)
        {
            var parameter = new MethodCallExpressionArgs()
            {
                IsMember = true, MemberValue = DateType.Year
            };
            var parameter2 = new MethodCallExpressionArgs()
            {
                IsMember = true, MemberName = value
            };
            var parameters = new MethodCallExpressionModel()
            {
                Args = new List <MethodCallExpressionArgs>()
                {
                    parameter2, parameter
                }
            };
            var begin = @"^";
            var end   = @"$";

            formatString = formatString.Replace("yyyy", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);
            formatString = formatString.Replace("yy", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);

            parameters.Args.Last().MemberValue = DateType.Month;
            formatString = formatString.Replace("MM", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);
            formatString = formatString.Replace("M", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);

            parameters.Args.Last().MemberValue = DateType.Day;
            formatString = formatString.Replace("dd", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);
            formatString = formatString.Replace("d", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);

            parameters.Args.Last().MemberValue = DateType.Hour;
            formatString = Regex.Replace(formatString, "hh", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end, RegexOptions.IgnoreCase);
            formatString = Regex.Replace(formatString, "h", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end, RegexOptions.IgnoreCase);

            parameters.Args.Last().MemberValue = DateType.Minute;
            formatString = formatString.Replace("mm", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);
            formatString = formatString.Replace("m", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);

            parameters.Args.Last().MemberValue = DateType.Second;
            formatString = formatString.Replace("ss", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);
            formatString = formatString.Replace("s", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);

            parameters.Args.Last().MemberValue = DateType.Millisecond;
            formatString = formatString.Replace("ms", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);
            var items = Regex.Matches(formatString, @"\^\d+\$").Cast <Match>().ToList();

            foreach (var item in items)
            {
                formatString = formatString.Replace(item.Value, "$@" + UtilMethods.ConvertNumbersToString(item.Value.TrimStart('^').TrimEnd('$')) + "$");
            }
            var strings             = formatString.TrimStart('$').TrimEnd('$').Split('$');
            var joinStringParameter = new MethodCallExpressionModel()
            {
                Args = new List <MethodCallExpressionArgs>()
            };

            foreach (var r in strings)
            {
                if (r.Substring(0, 1) == "@")
                {
                    joinStringParameter.Args.Add(new MethodCallExpressionArgs()
                    {
                        MemberName = r.TrimStart('@')
                    });
                }
                else
                {
                    var name = base.AppendParameter(r);
                    joinStringParameter.Args.Add(new MethodCallExpressionArgs()
                    {
                        MemberName = name
                    });
                }
            }
            return(this.GetMethodValue("MergeString", joinStringParameter).ObjToString());
        }