I'm building an application to translate string to lambda expression. For example, if the input is a string like "c.id>7 && c.grade<5"
, I should translate it to c=>c.id>7 && c.grade<5
; if the input is string like "c.id>7 && u.grade<5"
,I should translate it to (c,u)=>c.id>7 && u.grade<5
.
I'v built an application to recognize the string "c.id>7 && c.grade<5"
,and translate it to two expressions c=>c.id>7
and c=>c.grade<5
. But when I try to combine the two expressions together like below:
// expression1 is c=>c.id>7, expression1 is return by method Expression.Lambda
// expression2 is c=>c.grade<5 or u.grade<5, expression2 is return by method Expression.Lambda
Expression.AndAlso(expression1, expression2);
System said
there is no binary opertor AndAlso between System.Func`2[Test.user, System.Boolean] and System.Func`2[Test.user, System.Boolean]
So who can help me combine the two expressions together, thanks!
ps:
// expression1 and expression2 is built like below
Expression expression = Expression.Lambda(Expression.AndAlso(leftExpression, rightExpression), parameterExpressions.ToArray());