整理了一下表达式树的一些东西,入门足够了
先从ConstantExpression 开始一步一步的来吧 它表示具有常量值的表达式
我们选建一个控制台应用程序
ConstantExpression _constExp = Expression.Constant("aaa",typeof(string));//一个常量
//Console.Writeline("aaa");
MethodCallExpression _methodCallexp=Expression.Call(typeof(Console).GetMethod("WriteLine",new Type[]{typeof(string)}),_constExp);
Expression<Action> consoleLambdaExp = Expression.Lambda<Action>(_methodCallexp);
consoleLambdaExp.Compile()();
Console.ReadLine();下边的MethodCallExpression你也许不知道是什么回事,不要急我下边会详细讲的,这相当于