我有一个 Expression>
我想获取表达式的 DateTime 部分并从中提取月份。所以我会把它变成一个 Expression>
我不太确定如何做到这一点。我查看了 ExpressionTree Visitor 但我无法让它工作就像我需要的那样。这是日期时间表达式的示例
DateTimeExpression http://img442.imageshack.us/img442/ 6545/datetimeexpression.png
这是我想要创建的示例
MonthExpression http://img203.imageshack.us/img203/8013/datetimemonthexpression.png
看起来我需要创建一个新的 MemberExpression,它由 DateTime 表达式中的 Month 属性组成,但我不确定。
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.
发布评论
评论(1)
是的,这正是您想要的 - 并使用 < code>Expression.Property 是最简单的方法:
我相信应该没问题。它在这个简单的测试中有效:
Yes, that's exactly what you want - and using
Expression.Property
is the easiest way to do that:I believe that should be okay. It works in this simple test: