Example #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);
        }
Example #2
0
        static CustomExpressionTree SwapExp(CustomExpressionTree result)
        {
            var result2 = new CustomExpressionTree();

            while (result.Count > 0)
            {
                result2.Push(result.Pop());
            }
            return(result2);
        }
Example #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);
                }
            }
        }