private void Test2()
        {
            var Parsing = new ParsingExpressionTrees();

            Expression <Func <People, Student, Boolean> > where = (p, s) => (p.Amount > 4000 || s.Amount < 400) && p.Name.Length > 3 && s.Name.Length > 2;
            ExpressionReplaceType <Student, Teacher> replace1 = new ExpressionReplaceType <Student, Teacher>();
            var newWhere1 = replace1.ReplaceBodyType(where) as Expression <Func <People, Teacher, Boolean> >;
            var lambda1   = newWhere1.Compile();

            WriteLine(Parsing.ParsingExpression(newWhere1));
            ExpressionReplaceType <People, Teacher> replace2 = new ExpressionReplaceType <People, Teacher>();
            var newWhere2 = replace2.ReplaceBodyType(newWhere1) as Expression <Func <Teacher, Teacher, Boolean> >;
            var lambda2   = newWhere2.Compile();

            WriteLine(Parsing.ParsingExpression(newWhere2));
        }
        private void Test1()
        {
            var ParsingExpressionTrees          = new ParsingExpressionTrees();
            var ParasingExpressionTreeByVisitor = new ParsingExpressionTreeByVisitor();
            {
                ParameterExpression valueExp  = Expression.Parameter(typeof(int), "Value");                  //创建参数表达式 Value
                ParameterExpression resultExp = Expression.Parameter(typeof(int), "Result");                 //创建参数表达式 Result
                LabelTarget         lableExp  = Expression.Label(typeof(int), "Break");                      //创建一个标签以从循环跳转到,接收一个int类型的值
                BlockExpression     blockExp  = Expression.Block(                                            //创建代码块
                    new[] { resultExp }                                                                      //定义局部变量
                    , Expression.Assign(resultExp, Expression.Constant(1))                                   //给变量赋值
                    , Expression.Loop(                                                                       //定义循环体
                        Expression.IfThenElse(                                                               //创建条件表达式 if else
                            Expression.GreaterThanOrEqual(valueExp, Expression.Constant(1))                  //valueExp>=1
                            , Expression.MultiplyAssign(resultExp, Expression.PostDecrementAssign(valueExp)) // if true resultExp*=valueExp--
                            , Expression.Break(lableExp, resultExp)                                          // if else 跳转到lableExp,并将resultExp传入到跳转到lableExp
                            )
                        , lableExp                                                                           // 跳转到lableExp
                        )
                    );
                var lambda = Expression.Lambda <Func <int, int> >(blockExp, valueExp);
                int value  = lambda.Compile().Invoke(6);
                WriteLine("{0}:{1}", lambda.Body, value);

                WriteLine("lambda:{0}", ParsingExpressionTrees.ParsingExpression(lambda));

                WriteLine("==============================================================================");
                WriteLine("ParasingExpressionTreeByVisitor:");
                WriteLine("{0}", ParasingExpressionTreeByVisitor.Parsing(lambda));
                WriteLine("==============================================================================");
            }

            {
                Expression <Func <int, int> > lambda = num => num + 100;
                WriteLine("lambda :{0} ", ParsingExpressionTrees.ParsingExpression(lambda));
            }
        }
        public override void Test()
        {
            {
                Expression< Func<String, bool>> where = p => (p.ToLower() == "coho winery" || p.Length > 16);
                Expression<Func<String, int>> order = p => p.Length;

                 var Queryable = companies.Where(where.Compile()).OrderBy(order.Compile()).AsQueryable();
                WriteLine("companies.Where(company => (p.ToLower() == \"coho winery\" || p.Length > 16)).OrderBy(p => p.Length).AsQueryable():");
                foreach (var item in Queryable)
                {
                    WriteLine(item);
                }
                WriteLine("============================ParsingExpressionTrees==========================");
                WriteLine(parsing.ParsingExpression(where));
                WriteLine(parsing.ParsingExpression(order));
                WriteLine("======================================================");
                WriteLine("============================ParsingExpressionTreeByVisitor==========================");
                WriteLine(parsing2.Parsing(where));
                WriteLine(parsing2.Parsing(order));
                WriteLine("======================================================");
            }
            {
                var queryableData = companies.AsQueryable();
                var p1 = Expression.Parameter(typeof(IQueryable<String>), "queryableData");
                var p = Expression.Parameter(typeof(string), "p");
                var toLowerExp = Expression.Call(p, typeof(string).GetMethod("ToLower", new Type[0]));
                var lengthExp = Expression.Property(p, "Length");
                var exp1 = Expression.Equal(toLowerExp, Expression.Constant("coho winery",typeof(string)));
                var exp2 = Expression.GreaterThan(lengthExp, Expression.Constant(16, typeof(int)));

                var predicateBody = Expression.OrElse(exp1, exp2);

                //创建一个表达式表示:'queryableData.Where(p => (p.ToLower() == "coho winery" || p.Length > 16))
                MethodCallExpression whereCallExpression = Expression.Call(
                typeof(Queryable),
                "Where",
                new Type[] { queryableData.ElementType },
                queryableData.Expression,
                Expression.Lambda<Func<string, bool>>(predicateBody, new ParameterExpression[] { p }));
                
                MethodCallExpression orderByCallExpression = Expression.Call(
                    typeof(Queryable),
                    "OrderBy",
                    new Type[] { queryableData.ElementType, typeof(int) },
                    whereCallExpression,
                    Expression.Lambda<Func<String,int>>(lengthExp, new ParameterExpression[] { p }));


                WriteLine("============================ParsingExpressionTrees==========================");
                WriteLine(parsing.ParsingExpression(orderByCallExpression));
                WriteLine("======================================================");
                WriteLine("============================ParsingExpressionTreeByVisitor==========================");
                WriteLine(parsing2.Parsing(orderByCallExpression));
                WriteLine("======================================================");
                var Queryable = queryableData.Provider.CreateQuery<string>(orderByCallExpression);
                foreach (var item in Queryable)
                {
                    WriteLine(item);
                }

            }
        }