【发布时间】:2015-10-14 11:17:45
【问题描述】:
我有一个属性定义为Expression<Func<Kitten, object>>,即c => c.KittenAge,其中KittenAge 是int?
我想得到这个的类型。
我的代码是:
Expression<Func<Kitten, object>> property = c => c.KittenAge;
var unaryExpression = property.Body as UnaryExpression;
if (Nullable.GetUnderlyingType(unaryExpression.Type) == null)
{
// Error, must be nullable
}
不幸的是,总是会出现错误行,因为Type 是System.Object。如何从表达式中获取int? 的类型?
【问题讨论】:
标签: c# reflection lambda expression-trees