c# expression func automatically select return type

C#
// If property is something like an int or double and you want an object,
// you need to manually convert it to an object via another expression.
var parameter = Expression.Parameter(typeof(T));
var body = Expression.Property(parameter, propertyName);
var converted = Expression.Convert(body, typeof(object));
return Expression.Lambda<Func<T, object>>(converted, parameter);
Source

Also in C#: