Suppose I have the following LambdaExpression expression:
var itemParam = Expression.Parameter(typeof(Thing), "thing"); var someValue = "ABCXYZ123";
And I want the property name (2nd parameter) in the Expression.Property (...) factory element to be the parameter, how can I do this?
I was hoping to see a constructor that looks like this, but it doesn't exist:
Expresssion.Property(Expression instance, Expression propName)
Is there any trick I can do that can convert a parameterized ConstantExpression to the desired string or MemberInfo? Maybe I'm wrong.
My guess is that since these expression trees, when they are compiled, become lightweight ILs, this member access information is required, so element and property names must be provided when building expression trees.
Thanks for any tips!
EDIT: I wanted to add that this will be used as an argument for the Enumerable.Where (...) extension method to determine the correspondence for the relationship between two classes / entities.
source share