示例#1
0
        static CustomExpressionTree ProcessWhereStr(string whereStr)
        {
            var result        = new CustomExpressionTree();
            var junctionIndex = new List <Tuple <int, string> >();
            var index2        = 0;

            GetJunctionSort(whereStr, junctionIndex);
            var singleExps = whereStr.Split(junctionSplit, StringSplitOptions.RemoveEmptyEntries).ToList().Select(x => x.Replace(" ", "")).Where(x => x != "");

            foreach (var expression in singleExps)
            {
                var singleExp = expression.Split(OperSplit, StringSplitOptions.RemoveEmptyEntries).ToList().Select(x => x.Replace(" ", "")).ToArray();
                var subExp    = new CustomExpression {
                    ParameterName = singleExp[0], ParameterValue = singleExp[1]
                };
                var op = expression.Remove(expression.Length - singleExp[1].Length); //tail
                op        = op.Remove(0, singleExp[0].Length);                       // header
                subExp.Op = op;                                                      //operation in middle

                ProcessSubExp(subExp, result);
                if (index2 < junctionIndex.Count)
                {
                    var oper  = junctionIndex[index2];
                    var item2 = oper.Item2;
                    result.Push(item2);
                }
                index2++;
            }
            return(result);
        }
示例#2
0
        static void ProcessExp <TObj>(Expression pe, CustomExpression currExpress, IList <int> flagArr, IList <BinaryExpression> expressionList)
        {
            var leftPart = Expression.Property(pe, typeof(TObj).GetProperty(currExpress.ParameterName));
            var typ      = typeof(TObj).GetProperty(currExpress.ParameterName).PropertyType;

            var constCondition = Expression.Constant(System.Convert.ChangeType(currExpress.ParameterValue, typ), typ);

            CreateExpByOp(currExpress, expressionList, leftPart, constCondition);

            var lastFlag = (int)ConstJunction.Flag.NULL;

            if (flagArr.Count - 1 >= 0)
            {
                lastFlag = flagArr[flagArr.Count - 1];
            }
            if (lastFlag != (int)ConstJunction.Flag.NULL && lastFlag != (int)ConstJunction.Flag.Or && lastFlag != (int)ConstJunction.Flag.And)
            {
                flagArr.RemoveAt(flagArr.Count - 1);
            }
        }
示例#3
0
        static void ProcessSubExp(CustomExpression subExp, CustomExpressionTree result)
        {
            var index = 0;

            do
            {
                index = subExp.ParameterName.IndexOf(ConstBrace.LeftBrace);
                if (index < 0)
                {
                    break;
                }
                result.Push(ConstBrace.LeftBrace);
                subExp.ParameterName = subExp.ParameterName.Remove(index, 1);
            } while (index >= 0);

            var flagEnd       = false;
            var cntRightBrace = 0;

            index = 0;
            do
            {
                index = subExp.ParameterValue.IndexOf(ConstBrace.RightBrace);
                if (index < 0)
                {
                    break;
                }
                cntRightBrace++;
                subExp.ParameterValue = subExp.ParameterValue.Remove(index, 1);
                flagEnd = true;
            } while (index >= 0);

            result.Push(subExp);

            if (flagEnd)
            {
                while (cntRightBrace-- > 0)
                {
                    result.Push(ConstBrace.RightBrace);
                }
            }
        }
示例#4
0
        static void CreateExpByOp(CustomExpression currExpress, IList <BinaryExpression> expressionList, MemberExpression subLeft, ConstantExpression condition)
        {
            switch (currExpress.Op)
            {
            case ConstOper.GreaterEqual:
                expressionList.Add(Expression.GreaterThanOrEqual(subLeft, condition));
                break;

            case ConstOper.LessEqual:
                expressionList.Add(Expression.LessThanOrEqual(subLeft, condition));
                break;

            case ConstOper.Equal:
                expressionList.Add(Expression.Equal(subLeft, condition));
                break;

            case ConstOper.NoEqual:
                expressionList.Add(Expression.NotEqual(subLeft, condition));
                break;
            }
        }