Hi there I basically need a function with the following signature
Expression<Func<T, object>> GetPropertyLambda(string propertyName)
I have made a few attempts but the problem arise when the property is nullable
it goes something like this
ParameterExpression param = Expression.Parameter(typeof(T), "arg");
Expression member = Expression.Property(param, propertyName);
//this next section does conver if the type is wrong however
// when we get to Expression.Lambda it throws
Type typeIfNullable = Nullable.GetUnderlyingType(member.Type);
if (typeIfNullable != null)
{
member = Expression.Convert(member, typeIfNullable);
}
return Expression.Lambda<Func<T, object>>(member, param);
The Exception is
Expression of type 'System.Decimal' cannot be used for return type 'System.Object'
I would really apreciate some ideas and also why this doesnt work as expected
Thanks