I have a method that accepts a Expression<Func<T, object>>
instance. I want to get at the actual data type being returned by a specific expression instance, rather than object
.
I can get it to work for direct property references, so if I pass in the expression x => x.IntegerProperty
I can get a Type reference for an integer. This approach requires converting it to a MemberExpression.
However, I can't get it to work for arbitrary expressions. For instance, if the expression is x => x.IntegerProperty.ToString()
I want to get a Type reference for a string. I can't compile this to a MemberExpression, and if I just .Compile()
it and check the return type I get "object".
How can I look at the specific expression instance and derive the actual return type?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…