Consider this:
var propertyinfo = typeof(Customer).GetProperty(sortExpressionStr);
Type orderType = propertyinfo.PropertyType;
now i want to declare
Func<int,orderType>
i know its not possible directly since ordertype is at runtime but is there is any workarround ?
this is exactly what i want to do :
var propertyinfo = typeof(T).GetProperty(sortExpressionStr);
Type orderType = propertyinfo.PropertyType;
var param = Expression.Parameter(typeof(T), "x");
var sortExpression = (Expression.Lambda<Func<T, orderType >>
(Expression.Convert(Expression.Property(param, sortExpressionStr), typeof(orderType )), param));
all this because i want to convert:
Expression<Func<T,object>> to Expression<Func<T,orderType>>
or if its not possible then i want to create it from the first place with the right type , the case is as following :
im inside a method which have a type(Customer) and a property name of that type i want to order by it , i want to create a sort expression tree to pass it to Orderby(here)