Supating I with the following LambdaExpression:
var itemParam = Expression.Parameter(typeof(Thing), "thing");
var someValue = "ABCXYZ123"; // value to compare
LambdaExpression lex = Expression.Lambda(
Expression.Equal(
Expression.Property(itemParam, "Id"), // I want ID to be a Body expression parameter
Expression.Constant(someValue)
), itemParm);
And I want the property name (2nd parameter) in the Expression.Property(...) factory to be a parameter, how do I go about doing this?
我希望看到这样的建筑家,但现在还没有:
Expresssion.Property(Expression instance, Expression propName)
我能否把直截了当的压缩转化为必要的扼杀或成员。 Maybe 我这样说是错误的。
My hunch is that because these expression trees, when compiled, become lightweight IL, that member access information is required, thus, the names of members and properties must be provided when constructing expression trees.
感谢任何ti!
EDIT: Wanted to add that this will be used as an argument to the Enumerable.Where(...) extension method for determining a match on a relationship between two classes / entities.