Get "Object" return type from Func<MyClass, object>
c#, expression, lambda, reflection
Solution
You can get the return type like this:
f.Method.ReturnType
But this will return you the type `object`. If you want to get `Method` or `String` or something that derives from `object`, you won't be able to have the information unless you call the method.
Actually you could, but this would mean that you'd have to dissassemble the method core and then analyze it to see what the method can return. But even then, there might be many different return types.
So the answer is: if you want to know that it returns an object, then yes you can, otherwise it's not worth the trouble, and it's better to find another way of doing what you need.
Problem
Let's suppose I have defined Func as follows: ``` Func<MyClass, object> f = o => o.StringProperty; ``` or ``` Func<MyClass, object> f = o => o.Property.SomeMethod(); ``` Is there way to get the actual return type without specifically calling it?