I have an Expression<Func<T,DateTime>> I want to take the DateTime part of the expression and pull the Month off of it. So I would be turning it into a Expression<Func<T,int>> I’m not really sure how to do this. I looked at the ExpressionTree Visitor but I can’t get it to work like I need. Here is an example of the DateTime Expression
DateTimeExpression http://img442.imageshack.us/img442/6545/datetimeexpression.png
Here is an example of what I want to create
MonthExpression http://img203.imageshack.us/img203/8013/datetimemonthexpression.png
It looks like I need to create a new MemberExpression that is made up of the Month property from the DateTime expression but I’m not sure.
Yes, that’s exactly what you want – and using
Expression.Propertyis the easiest way to do that:I believe that should be okay. It works in this simple test: