We have an entity of type T1
which has a member of type T
.
something like this :
public class T1
{
public T Member{get;set;}
}
User can use our UI to give us a filter over T and we have translate it to an expression of a function that gets a T and returns bool (Expression<Func<T,bool>>)
I would like to know is it possible to convert this to an expression of a function that gets T1 and returns bool.
Actually I'd like to convert this :
(t=>t.Member1==someValue && t.Member2==someOtherValue);
to this :
(t1=>t1.Member.Member1==someValue && t1.Member.Member2==someOtherValue);
You can do it with a few way.
First and simplest: use Expression.Invoke
but in this case you get not
instead of
For replacing you can use ExpressionVisitor class like
and use it
Given
plus
and
you can
The
ExpressionReplacer
class replaces a parameter of an expression with another expression, while theReplace
method uses theExpressionReplacer
and then rebuilds a new expression.