Generic unboxing expressions <Func <T, object >> for expression <Func <T, TResult >>

As mentioned in the header, I have an expression in which the type of the result is β€œstored” in object , which may be all of my domain classes. Is there a way to get a specific expression (unboxing)?

+2
source share
1 answer

If I understand your question correctly, then you can look for Expression.Convert

 Expression<Func<T,object>> original = // ... something Expression<Func<T,TResult>> converted = Expression.Lambda<Func<T,TResult>>( Expression.Convert(original.Body,typeof(TResult)), original.Parameters); 

Demo on ideon.

+3
source

All Articles