我正在尝试创建以下形式的表达式:
f => f.Number;
当我尝试创建表达式时:
var _sourceParameter = Expression.Parameter(typeof(Organisation));
var propertyReference = Expression.Property(_sourceParameter, "Number");
var lambdaExpression = Expression.Lambda<Func<Organisation, object>>(propertyReference, _sourceParameter);
我得到以下异常:
Expression of type 'System.Int32' cannot be used for return type 'System.Object'
我怎样才能实现这一目标?