我想创建一个动态的
Expression<Func<T,Y>>
。以下代码适用于字符串,但不适用于日期时间。我的意思是,我会得到这个异常:有人能分析一下错误吗?"Expression of type 'System.Nullable`1[System.DateTime]' cannot be used for return type 'System.Object'"
Type type = typeof(DSVPNProjection);
ParameterExpression arg = Expression.Parameter(type, "x");
Expression expr = arg;
PropertyInfo propertyInfo = type.GetProperty(sidx);
expr = Expression.Property(expr, propertyInfo);
var expression =
Expression.Lambda<Func<DSVPNProjection, object>>(expr, arg);
我需要将object
更改为其他类型吗?如果是,那应该更改为哪种类型呢?正如您所看到的,我正在尝试动态获取PropertyInfo并将其用作Func的第二个参数。