前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >原 Expression Trees学习

原 Expression Trees学习

作者头像
魂祭心
发布2018-05-17 17:40:49
7990
发布2018-05-17 17:40:49
举报
文章被收录于专栏:魂祭心魂祭心魂祭心

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Linq.Expressions;

using System.Reflection;

using System.Runtime.CompilerServices;

using System.Windows.Forms;

using System.Threading;

namespace Expressionss

{

    class Program

    {

        static void Main(string[] args)

        {

            Console.WriteLine("*******************************************************************");

            Console.WriteLine("***** BlockExpression                 ConditionalExpression *******");

            Console.WriteLine("***** ConstantExpression              DebugInfoExpression   *******");

            Console.WriteLine("***** DefaultExpression               DynamicExpression     *******");

            Console.WriteLine("***** GotoExpression                  IndexExpression       *******");

            Console.WriteLine("***** InvocationExpression            LabelExpression       *******");

            Console.WriteLine("***** LambdaExpression                ListInitExpression    *******");

            Console.WriteLine("***** LoopExpression                  MemberExpression      *******");

            Console.WriteLine("***** MemberInitExpression            MethodCallExpression  *******");

            Console.WriteLine("***** NewArrayExpression              NewExpression         *******");

            Console.WriteLine("***** ParameterExpression             TryExpression         *******");

            Console.WriteLine("***** RuntimeVariablesExpression      SwitchExpression      *******");

            Console.WriteLine("***** TypeBinaryExpression            UnaryExpression       *******");

            Console.WriteLine("***** BinaryExpression                                       ******");

            Console.WriteLine("*******************************************************************");

            Thread th = new Thread(start);

            th.Start();

        }

        public static void BlockExpressionTest()

        {

            Console.WriteLine("//System.Linq.Expressions.BlockExpression                 表示一个包含可在其中定义变量的表达式序列的块。");

            BlockExpression blockExpr = Expression.Block(

    Expression.Call(

        null,

        typeof(Console).GetMethod("Write", new Type[] { typeof(String) }),

        Expression.Constant("Hello ")

       ),

    Expression.Call(

        null,

        typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }),

        Expression.Constant("World!")

        ),

    Expression.Constant(42)

);

            Console.WriteLine("The result of executing the expression tree:");

            var result = Expression.Lambda<Func<int>>(blockExpr).Compile()();

            Console.WriteLine("The expressions from the block expression:");

            foreach (var expr in blockExpr.Expressions)

                Console.WriteLine(expr.ToString());

            Console.WriteLine("The return value of the block expression:");

            Console.WriteLine(result);

        }

        public static void BinaryExpressionTest()

        {

            Console.WriteLine("//System.Linq.Expressions.BinaryExpression               表示包含二元运算符的表达式");

            System.Linq.Expressions.BinaryExpression binaryExpression =

    System.Linq.Expressions.Expression.MakeBinary(

        System.Linq.Expressions.ExpressionType.Subtract,

        System.Linq.Expressions.Expression.Constant(53),

        System.Linq.Expressions.Expression.Constant(14));

            Expression<Func<int>> lambdaExp =

Expression.Lambda<Func<int>>(binaryExpression);

            Console.WriteLine(lambdaExp.Compile().Invoke());

            Console.WriteLine(binaryExpression.ToString());

        }

        public static void UnaryExpressionTest()

        {

            Console.WriteLine("//System.Linq.Expressions.UnaryExpression             表示包含一元运算符的表达式。");

            System.Linq.Expressions.UnaryExpression typeAsExpression =

            System.Linq.Expressions.Expression.TypeAs(

            System.Linq.Expressions.Expression.Constant(34, typeof(int)),

            typeof(int?));

            Expression<Func<int?>> lambdaExp =

            Expression.Lambda<Func<int?>>(typeAsExpression);

            lambdaExp.Compile();

            Console.WriteLine(lambdaExp.Compile().Invoke());

        }

        public static void TryExpressionTest()

        {

            Console.WriteLine("//System.Linq.Expressions.TryExpression");

            TryExpression tryCatchExpr =

    Expression.TryCatch(

        Expression.Block(

            Expression.Throw(Expression.Constant(new DivideByZeroException())),

            Expression.Constant("Try block")

        ),

        Expression.Catch(

            typeof(DivideByZeroException),

            Expression.Constant("Catch block")

        )

    );

            Console.WriteLine(Expression.Lambda<Func<string>>(tryCatchExpr).Compile()());

        }

        public static void SwitchExpressionTest()

        {

            Console.WriteLine("//System.Linq.Expressions.SwitchExpression          表示一个控制表达式,该表达式通过将控制传递到 SwitchCase 来处理多重选择。");

            ConstantExpression switchValue = Expression.Constant(1);

            SwitchExpression switchExpr =

                Expression.Switch(

                    switchValue,

                    Expression.Call(                     //默认

                                null,

                                typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }),

                                Expression.Constant("Default")

                            ),

                    new SwitchCase[] {                 //非默认所有情况

            Expression.SwitchCase(                     //情况1

                Expression.Call(      

                    null,

                    typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }),  //条件达成处理的内容

                    Expression.Constant("First")       //条件

                ),

                Expression.Constant(1)

            ),

            Expression.SwitchCase(

                Expression.Call(

                    null,

                    typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }),

                    Expression.Constant("Second")

                ),

                Expression.Constant(2)

            )

        }

                );

            Expression.Lambda<Action>(switchExpr).Compile()();

        }

        public static void NewArrayExpressionTest()

        {

            Console.WriteLine("//System.Linq.Expressions.NewArrayExpression");

            List<System.Linq.Expressions.Expression> trees =

    new List<System.Linq.Expressions.Expression>()

        { System.Linq.Expressions.Expression.Constant("oak"),

          System.Linq.Expressions.Expression.Constant("fir"),

          System.Linq.Expressions.Expression.Constant("spruce"),

          System.Linq.Expressions.Expression.Constant("alder") };

            System.Linq.Expressions.NewArrayExpression newArrayExpression =

                  System.Linq.Expressions.Expression.NewArrayInit(typeof(string), trees);

            Expression<Func<string>> lambdaExp =

            Expression.Lambda<Func<string>>(Expression.ArrayIndex(newArrayExpression, Expression.Constant(1))

            );

            Console.WriteLine(lambdaExp.Compile().Invoke());

            Console.WriteLine(newArrayExpression.ToString());

        }

        public static void MethodCallExpressionText()

        {

            Console.WriteLine("//System.Linq.Expressions.MethodCallExpression      表示对静态方法或实例方法的调用。");

            string[,] gradeArray = { { "chemistry", "history", "mathematics" }, { "78", "61", "82" } };

            System.Linq.Expressions.Expression arrayExpression =

                System.Linq.Expressions.Expression.Constant(gradeArray);

            System.Linq.Expressions.MethodCallExpression methodCallExpression =

                System.Linq.Expressions.Expression.ArrayIndex(

                    arrayExpression,

                    System.Linq.Expressions.Expression.Constant(0),

                    System.Linq.Expressions.Expression.Constant(2));

            Expression<Func<string>> lambdaExp =

            Expression.Lambda<Func<string>>(methodCallExpression);

            Console.WriteLine(lambdaExp.Compile().Invoke());

            //等价于:   gradeArray.GetValue(0,2)

        }

        public static void MemberInitExpressionTest()

        {

            Console.WriteLine(@"//System.Linq.Expressions.MemberInitExpression      表示调用构造函数并初始化新对象的一个或多个成员。

//System.Linq.Expressions.NewExpression             表示构造函数调用。

//System.Linq.Expressions.ParameterExpression       表示命名的参数表达式");

            System.Reflection.MemberInfo weightMember =

            typeof(Car).GetMember("Weight")[0];

            System.Reflection.MemberInfo heightMember =

                typeof(Car).GetMember("Height")[0];                //成员

            ParameterExpression params1 = Expression.Parameter(typeof(int), "weight");

            ParameterExpression params2 = Expression.Parameter(typeof(int), "height");

            ConstructorInfo info = typeof(Car).GetConstructor(new Type[] { typeof(Int32), typeof(Int32) });

            System.Linq.Expressions.NewExpression car =

            System.Linq.Expressions.Expression.New(info, params1, params2);

            System.Linq.Expressions.MemberBinding weightMemberBinding =

                System.Linq.Expressions.Expression.Bind(

                    weightMember,

                    params1);

            System.Linq.Expressions.MemberBinding heightMemberBinding =

                System.Linq.Expressions.Expression.Bind(

                    heightMember,

                   params2);

            System.Linq.Expressions.MemberInitExpression memberInitExpression =

                System.Linq.Expressions.Expression.MemberInit(

                    car,

                    weightMemberBinding,

                    heightMemberBinding);

            Expression<Action<int, int>> lambdaExp =

            Expression.Lambda<Action<int, int>>(memberInitExpression, new ParameterExpression[] { params1, params2 });

            lambdaExp.Compile().Invoke(123, 1234);

            Console.WriteLine(memberInitExpression.ToString());

        }

        public static void MemberExpressionTest()

        {

            Console.WriteLine("//System.Linq.Expressions.MemberExpression           表示访问字段或属性。");

            Car car = new Car();

            System.Linq.Expressions.MemberExpression memberExpression =

                System.Linq.Expressions.Expression.Field(

                    System.Linq.Expressions.Expression.Constant(car),

                    "Weight");

            Console.WriteLine(memberExpression.Member.ToString());

        }

        public static void LoopExpressionTest()

        {

            Console.WriteLine("//System.Linq.Expressions.LoopExpression;       //  表示无限循环。 可以使用“break”退出它。");

            ParameterExpression value = Expression.Parameter(typeof(int), "value");

            ParameterExpression result = Expression.Parameter(typeof(int), "result");

            LabelTarget label = Expression.Label(typeof(int));           //中断

            BlockExpression block = Expression.Block(

                new[] { result },

                Expression.Assign(result, Expression.Constant(1)),      //赋值

                    Expression.Loop(                                    //循环加选择

                       Expression.IfThenElse(

                           Expression.GreaterThan(value, Expression.Constant(1)),

                           Expression.MultiplyAssign(result,

                               Expression.PostDecrementAssign(value)),

                           Expression.Break(label, result)

                       ),

                   label

                )

            );

            int factorial = Expression.Lambda<Func<int, int>>(block, value).Compile()(5);

            Console.WriteLine(factorial);

            //等价语句

            //int value = 5;

            //int result = 1;

            //int factorial=0;

            //while (true)

            //{

            //    if (value > 1)

            //    {

            //        result *= value;

            //        value--;

            //    }

            //    else

            //    {

            //        factorial = result;

            //        break;

            //    }

            //}

        }

        public static void ListInitExpressionTest()

        {

            Console.WriteLine("//System.Linq.Expressions.ListInitExpression 表示包含集合初始值设定项的构造函数调用。");

            string tree1 = "maple";

            string tree2 = "oak";

            System.Reflection.MethodInfo addMethod = typeof(Dictionary<int, string>).GetMethod("Add");//获得Dictionary的Add方法

            System.Linq.Expressions.ElementInit elementInit1 =     // 表示 IEnumerable 集合的单个元素的初始值设定项。

                System.Linq.Expressions.Expression.ElementInit(

                    addMethod,

                    System.Linq.Expressions.Expression.Constant(tree1.Length),

                    System.Linq.Expressions.Expression.Constant(tree1));

            System.Linq.Expressions.ElementInit elementInit2 =

                System.Linq.Expressions.Expression.ElementInit(

                    addMethod,

                    System.Linq.Expressions.Expression.Constant(tree2.Length),

                    System.Linq.Expressions.Expression.Constant(tree2));

            System.Linq.Expressions.NewExpression newDictionaryExpression =

                System.Linq.Expressions.Expression.New(typeof(Dictionary<int, string>));//构造函数

            System.Linq.Expressions.ListInitExpression listInitExpression =

                System.Linq.Expressions.Expression.ListInit(

                    newDictionaryExpression,

                    elementInit1,

                    elementInit2);

            ElementInit el = listInitExpression.Initializers[0];   //获取ElementInit

            Console.WriteLine("" + el.Arguments[0] + el.Arguments[1]);

            Console.WriteLine(listInitExpression.ToString());

        }

        public static void LambdaExpressionTest()

        {

            Console.WriteLine("//System.Linq.Expressions.LambdaExpression       描述一个 lambda 表达式。 这将捕获与 .NET 方法体类似的代码块。");

            ParameterExpression paramExpr = Expression.Parameter(typeof(int), "arg");//参数

            ParameterExpression paramExpr1 = Expression.Parameter(typeof(int), "arg2");//参数

            Expression<Func<int, int, int>> expr = (num, num1) => num * num;

            LambdaExpression lambdaExpr = Expression.Lambda(

                typeof(Func<int, int, int>),

                Expression.Invoke(expr, paramExpr, paramExpr1),

                paramExpr,

                paramExpr1

            );

            Console.WriteLine(lambdaExpr);

            Console.WriteLine(lambdaExpr.Compile().DynamicInvoke(12, 12));

        }

        public static void InvocationExpressionTest()

        {

            Console.WriteLine("//System.Linq.Expressions.InvocationExpression         表示将委托或 lambda 表达式应用于参数表达式列表的表达式。");

            System.Linq.Expressions.Expression<Func<int, int, bool>> largeSumTest =

           (num1, num2) => (num1 + num2) > 1000;

            System.Linq.Expressions.InvocationExpression invocationExpression =

                System.Linq.Expressions.Expression.Invoke(               //调用lambda 表达式

                    largeSumTest,                                        //语句

                    System.Linq.Expressions.Expression.Constant(539),    //参数1

                    System.Linq.Expressions.Expression.Constant(281));   //参数2

            Console.WriteLine(invocationExpression.ToString());

            //调用运行

            Expression<Func<bool>> ss = Expression.Lambda<Func<bool>>(invocationExpression);

            Console.WriteLine(ss.Compile().Invoke());

        }

        public static void IndexExpressionTest()

        {

            Console.WriteLine("//System.Linq.Expressions.IndexExpression                  表示编制属性或数组的索引。");

            ParameterExpression arrayExpr = Expression.Parameter(typeof(int[]), "Array");

            ParameterExpression indexExpr = Expression.Parameter(typeof(int), "Index");

            ParameterExpression valueExpr = Expression.Parameter(typeof(int), "Value");

            //参数

            Expression arrayAccessExpr = Expression.ArrayAccess(

                arrayExpr,

                indexExpr

            );                  //取出数组indexexpr位置的数

            //数组

            Expression<Func<int[], int, int, int>> lambdaExpr = Expression.Lambda<Func<int[], int, int, int>>(

                Expression.Assign(arrayAccessExpr, Expression.Add(arrayAccessExpr, valueExpr)),   //实现加减

                arrayExpr,

                indexExpr,

                valueExpr

            );

            Console.WriteLine("Array Access Expression:");

            Console.WriteLine(arrayAccessExpr.ToString());

            Console.WriteLine("Lambda Expression:");

            Console.WriteLine(lambdaExpr.ToString());

            Console.WriteLine("The result of executing the lambda expression:");

            Console.WriteLine(lambdaExpr.Compile().Invoke(new int[] { 10, 20, 30 }, 2, 5));

            //等同于

            // public int add(int[] arrayExpr, int indexExpr, int valueExpr)

            //{

            // int temp = arrayExpr[indexExpr];

            // temp = temp + valueExpr;

            // return temp;

            // }

        }

        public static void GotoExpressionTest()

        {

            Console.WriteLine("//System.Linq.Expressions.GotoExpression                   表示无条件跳转。 这包括 return 语句、break 和 continue 语句以及其他跳转。");

            //System.Linq.Expressions.LabelExpression           表示一个标签,可以将该标签放置在任何 Expression 上下文中。 如果已跳转到该标签,则它将获取由对应的 GotoExpression 提供的值。 否则,它接收 DefaultValue 中的值。 如果 Type 等于 System.Void,则不应提供值。

            LabelTarget returnTarget = Expression.Label();

            BlockExpression blockExpr =

                Expression.Block(

                    Expression.Call(typeof(Console).GetMethod("WriteLine", new Type[] { typeof(string), typeof(object), typeof(object), typeof(object) }), new Expression[] { Expression.Constant("匹配参数{0},匹配参数{1},匹配参数{2}"), Expression.Constant("1"), Expression.Constant("2"), Expression.Constant("3") }),

                    Expression.Goto(returnTarget),

                    Expression.Call(typeof(Console).GetMethod("WriteLine", new Type[] { typeof(string) }), Expression.Constant("Other Work")),//阻断,

                    Expression.Label(returnTarget)

                );

            Expression.Lambda<Action>(blockExpr).Compile()();

        }

        public static void ConstantExpression()

        {

            Console.WriteLine("//System.Linq.Expressions.ConstantExpression             表示具有常量值的表达式。");

            Expression constantExpr = Expression.Constant(5.5);

            Console.WriteLine(constantExpr.ToString());

            double num2 = 3.5;

            constantExpr = Expression.Constant(num2);

            Console.WriteLine(constantExpr.ToString());

            //System.Linq.Expressions.DebugInfoExpression             发出或清除调试信息的序列点。 这允许调试器在调试时突出显示正确的源代码。         

            //System.Linq.Expressions.DefaultExpression               表示类型或空表达式的默认值。

            Expression defaultExpr = Expression.Default(

                            typeof(Int32)

                        );

            Console.WriteLine(defaultExpr.ToString());

            Console.WriteLine(

                Expression.Lambda<Func<Int32>>(defaultExpr).Compile()());

        }

        public static void ConditionalExpressionText()

        {

            Console.WriteLine("//System.Linq.Expressions.ConditionalExpression          表示包含条件运算符的表达式。");

            int num = 100;

            Expression conditionExpr = Expression.Condition(

                                       Expression.Constant(num > 10),

                                       Expression.Constant("num is greater than 10"),

                                       Expression.Constant("num is smaller than 10")

                                     );

            Console.WriteLine(conditionExpr.ToString());

            Console.WriteLine(

            Expression.Lambda<Func<string>>(conditionExpr).Compile()());

        }

        public static void start()

        {

            Application.EnableVisualStyles();

            Application.SetCompatibleTextRenderingDefault(false);

            Application.Run(new MyForm());

        }

        public static void Default(string mess)

        {

            Console.WriteLine(mess);

        }

    }

    public class Car

    {

        private Int32 weight;

        private Int32 height;

        public Car()

        {

            weight = 100;

        }

        public Car(Int32 params1, Int32 params2)

        {

            weight = params1;

            height = params2;

        }

        public Int32 Weight

        {

            get { return weight; }

            set { weight = value; }

        }

        public Int32 Height

        {

            get { return height; }

            set { height = value; }

        }

    }

    #region 窗体代码  不必看

    public class MyForm : Form

    {

        private System.ComponentModel.IContainer components = null;

        public MyForm()

        {

            this.components = new System.ComponentModel.Container();

            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

            this.Text = "Form1";

            this.Width = 460;

            this.Height = 400;

            Label lab = new Label();

            lab.Location = new System.Drawing.Point(120, 310);

            lab.Text = "by 魂祭心";

            Button btn1 = new Button();

            btn1.Size = new System.Drawing.Size(100, 30);

            btn1.Location = new System.Drawing.Point(10, 10);

            btn1.Text = "BinaryExpression";

            btn1.Click += (sender, e) => { Program.BinaryExpressionTest(); Program.Default("————————————————我是分割线"); };

            Button btn2 = new Button();

            btn2.Size = new System.Drawing.Size(100, 30);

            btn2.Location = new System.Drawing.Point(120, 10);

            btn2.Text = "BlockExpression";

            btn2.Click += (sender, e) => { Program.BlockExpressionTest(); Program.Default("————————————————我是分割线"); };

            Button btn3 = new Button();

            btn3.Size = new System.Drawing.Size(100, 30);

            btn3.Location = new System.Drawing.Point(230, 10);

            btn3.Text = "ConditionalExpression";

            btn3.Click += (sender, e) => { Program.ConditionalExpressionText(); Program.Default("————————————————我是分割线"); };

            Button btn4 = new Button();

            btn4.Size = new System.Drawing.Size(100, 30);

            btn4.Location = new System.Drawing.Point(340, 10);

            btn4.Text = "ConstantExpression";

            btn4.Click += (sender, e) => { Program.ConstantExpression(); Program.Default("————————————————我是分割线"); };

            Button btn5 = new Button();

            btn5.Size = new System.Drawing.Size(100, 30);

            btn5.Location = new System.Drawing.Point(10, 60);

            btn5.Text = "DebugInfoExpression";

            btn5.Click += (sender, e) => { Program.Default("尚未完成DebugInfoExpression"); Program.Default("————————————————我是分割线"); };

            Button btn6 = new Button();

            btn6.Size = new System.Drawing.Size(100, 30);

            btn6.Location = new System.Drawing.Point(120, 60);

            btn6.Text = "DefaultExpression";

            btn6.Click += (sender, e) => { Program.Default("尚未完成DefaultExpression"); Program.Default("————————————————我是分割线"); };

            Button btn7 = new Button();

            btn7.Size = new System.Drawing.Size(100, 30);

            btn7.Location = new System.Drawing.Point(230, 60);

            btn7.Text = "DynamicExpression ";

            btn7.Click += (sender, e) => { Program.Default("尚未完成DynamicExpression"); Program.Default("————————————————我是分割线"); };

            Button btn8 = new Button();

            btn8.Size = new System.Drawing.Size(100, 30);

            btn8.Location = new System.Drawing.Point(340, 60);

            btn8.Text = "BlockExpression";

            btn8.Click += (sender, e) => { Program.GotoExpressionTest(); Program.Default("————————————————我是分割线"); };

            Button btn9 = new Button();

            btn9.Size = new System.Drawing.Size(100, 30);

            btn9.Location = new System.Drawing.Point(10, 110);

            btn9.Text = "GotoExpression ";

            btn9.Click += (sender, e) => { Program.BlockExpressionTest(); Program.Default("————————————————我是分割线"); };

            Button btn10 = new Button();

            btn10.Size = new System.Drawing.Size(100, 30);

            btn10.Location = new System.Drawing.Point(120, 110);

            btn10.Text = "IndexExpression";

            btn10.Click += (sender, e) => { Program.IndexExpressionTest(); Program.Default("————————————————我是分割线"); };

            Button btn11 = new Button();

            btn11.Size = new System.Drawing.Size(100, 30);

            btn11.Location = new System.Drawing.Point(230, 110);

            btn11.Text = "InvocationExpression";

            btn11.Click += (sender, e) => { Program.InvocationExpressionTest(); Program.Default("————————————————我是分割线"); };

            Button btn12 = new Button();

            btn12.Size = new System.Drawing.Size(100, 30);

            btn12.Location = new System.Drawing.Point(340, 110);

            btn12.Text = "LabelExpression";

            btn12.Click += (sender, e) => { Program.GotoExpressionTest(); Program.Default("————————————————我是分割线"); };

            Button btn13 = new Button();

            btn13.Size = new System.Drawing.Size(100, 30);

            btn13.Location = new System.Drawing.Point(10, 160);

            btn13.Text = "LambdaExpression";

            btn13.Click += (sender, e) => { Program.LambdaExpressionTest(); Program.Default("————————————————我是分割线"); };

            Button btn14 = new Button();

            btn14.Size = new System.Drawing.Size(100, 30);

            btn14.Location = new System.Drawing.Point(120, 160);

            btn14.Text = "ListInitExpression";

            btn14.Click += (sender, e) => { Program.ListInitExpressionTest(); Program.Default("————————————————我是分割线"); };

            Button btn15 = new Button();

            btn15.Size = new System.Drawing.Size(100, 30);

            btn15.Location = new System.Drawing.Point(230, 160);

            btn15.Text = "LoopExpression ";

            btn15.Click += (sender, e) => { Program.LoopExpressionTest(); Program.Default("————————————————我是分割线"); };

            Button btn16 = new Button();

            btn16.Size = new System.Drawing.Size(100, 30);

            btn16.Location = new System.Drawing.Point(340, 160);

            btn16.Text = "MemberExpression";

            btn16.Click += (sender, e) => { Program.MemberExpressionTest(); Program.Default("————————————————我是分割线"); };

            Button btn17 = new Button();

            btn17.Size = new System.Drawing.Size(100, 30);

            btn17.Location = new System.Drawing.Point(10, 210);

            btn17.Text = "MemberInitExpression";

            btn17.Click += (sender, e) => { Program.MemberInitExpressionTest(); Program.Default("————————————————我是分割线"); };

            Button btn18 = new Button();

            btn18.Size = new System.Drawing.Size(100, 30);

            btn18.Location = new System.Drawing.Point(120, 210);

            btn18.Text = "MethodCallExpression ";

            btn18.Click += (sender, e) => { Program.MethodCallExpressionText(); Program.Default("————————————————我是分割线"); };

            Button btn19 = new Button();

            btn19.Size = new System.Drawing.Size(100, 30);

            btn19.Location = new System.Drawing.Point(230, 210);

            btn19.Text = "NewArrayExpression";

            btn19.Click += (sender, e) => { Program.NewArrayExpressionTest(); Program.Default("————————————————我是分割线"); };

            Button btn20 = new Button();

            btn20.Size = new System.Drawing.Size(100, 30);

            btn20.Location = new System.Drawing.Point(340, 210);

            btn20.Text = "NewExpression";

            btn20.Click += (sender, e) => { Program.MemberInitExpressionTest(); Program.Default("————————————————我是分割线"); };

            Button btn21 = new Button();

            btn21.Size = new System.Drawing.Size(100, 30);

            btn21.Location = new System.Drawing.Point(10, 260);

            btn21.Text = "ParameterExpression";

            btn21.Click += (sender, e) => { Program.MemberInitExpressionTest(); Program.Default("————————————————我是分割线"); };

            Button btn22 = new Button();

            btn22.Size = new System.Drawing.Size(100, 30);

            btn22.Location = new System.Drawing.Point(120, 260);

            btn22.Text = "RuntimeVariablesExpression";

            btn22.Click += (sender, e) => { Program.Default("RuntimeVariablesExpression未完成"); Program.Default("————————————————我是分割线"); };

            Button btn23 = new Button();

            btn23.Size = new System.Drawing.Size(100, 30);

            btn23.Location = new System.Drawing.Point(230, 260);

            btn23.Text = "SwitchExpression";

            btn23.Click += (sender, e) => { Program.SwitchExpressionTest(); Program.Default("————————————————我是分割线"); };

            Button btn24 = new Button();

            btn24.Size = new System.Drawing.Size(100, 30);

            btn24.Location = new System.Drawing.Point(340, 260);

            btn24.Text = "TryExpression";

            btn24.Click += (sender, e) => { Program.TryExpressionTest(); Program.Default("————————————————我是分割线"); };

            Button btn25 = new Button();

            btn25.Size = new System.Drawing.Size(100, 30);

            btn25.Location = new System.Drawing.Point(10, 310);

            btn25.Text = "UnaryExpression";

            btn25.Click += (sender, e) => { Program.UnaryExpressionTest(); Program.Default("————————————————我是分割线"); };

            this.Controls.Add(btn1);

            this.Controls.Add(btn2);

            this.Controls.Add(btn3);

            this.Controls.Add(btn4);

            this.Controls.Add(btn5);

            this.Controls.Add(btn6);

            this.Controls.Add(btn7);

            this.Controls.Add(btn8);

            this.Controls.Add(btn9);

            this.Controls.Add(btn10);

            this.Controls.Add(btn11);

            this.Controls.Add(btn12);

            this.Controls.Add(btn13);

            this.Controls.Add(btn14);

            this.Controls.Add(btn15);

            this.Controls.Add(btn16);

            this.Controls.Add(btn17);

            this.Controls.Add(btn18);

            this.Controls.Add(btn19);

            this.Controls.Add(btn20);

            this.Controls.Add(btn21);

            this.Controls.Add(btn22);

            this.Controls.Add(btn23);

            this.Controls.Add(btn24);

            this.Controls.Add(btn25);

            this.Controls.Add(lab);

        }

        protected override void Dispose(bool disposing)

        {

            if (disposing && (components != null))

            {

                components.Dispose();

            }

            base.Dispose(disposing);

        }

    }

    #endregion

}

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档