linq 表达式树的构建 Expression.Lambda
遇到个问题
http://topic.csdn.net/u/20100419/11/0fd531ee-3ecb-4c82-a75e-d06c392202db.html?1713776579
解决方法
http://topic.csdn.net/u/20100413/17/88bb3a5f-fe4e-4370-851c-7a007a781653.html
ParameterExpression numParam = Expression.Parameter(typeof(string), "str");
ConstantExpression b = Expression.Constant(true, typeof(bool));
MethodCallExpression methodCall = Expression.Call(typeof(string).GetMethod("IsNullOrEmpty"), numParam);
BinaryExpression isEqual = Expression.NotEqual(methodCall, b);
Expression<Func<string, bool>> lambda1 =
Expression.Lambda<Func<string, bool>>(
isEqual,
new ParameterExpression[] { numParam });
对应的Lambel 是
C# code
-
str => string.IsNullOrEmpty(str)!=true
===================================================================ParameterExpression strParam = Expression.Parameter(typeof(string), "str"); MethodInfo cMe = typeof(string).GetMethod("Contains"); ConstantExpression ce = Expression.Constant("a",typeof(string)); MethodCallExpression call = Expression.Call(strParam, cMe, ce); Expression<Func<string, bool>> lam = Expression.Lambda<Func<string, bool>>(call, strParam);随笔