有什么干净的方法可以PropertyDescriptor
从表达式树中获取一个?
我目前有PropertyInfo
,但理想情况下我想要PropertyDescriptor
我的代码:
var prop =
(System.Reflection.PropertyInfo)
((MemberExpression)
((Expression<Func<TestClass, long>>)
(p => p.ID)).Body).Member;
我需要 PropertyDescriptor 是因为我需要使用:
if (prop.CanResetValue(this))
{
prop.ResetValue(this);
}
else
{
prop.SetValue(this, null);
}
我不能使用PropertyInfo.SetValue(this, null, null)
,因为它不适合我的需要,因为我需要重置为DefaultValueAttribute
.