I want to build an expression for a Where clause
Expression<Func<T, bool>>
on a method that accepts a parameter of type
Expression<Func<T, DateTime>>
I want to manipulate my DateTime property to compare its internal properties like to add compare clauses to day, month and year properties.
My method is like the following:
public static class MyUtils
{
public static Expression<Func<T, bool>> GetTime<T>(this Expression<Func<T, bool>> pExp, Expression<Func<T, DateTime>> MyProperty, int day, int month, int year)
{
}
}
I’d like to use it like this:
Expression<Func<MyClass, bool>> vExpression = p => false;
vExpression = vExpression.GetTime<MyClass>(c => c.MyDate, 21, 12, 2012);
So at the end of the method I have some comparisons between my “MyDate” property and the individual date values.
Can this be done?
Perhaps something like this:
You can then do:
EDIT
The above code shows how you can create a new expression tree based on the old one. You can create your new expression tree using any allowed constructs. Here is a slightly more complicated example: