我使用Expression<Func<TEntity, object>>
映射属性。
我只需要从对象中获取属性值,直到知道为止。如何使用该表达式分配值?
答案 0 :(得分:1)
尝试此操作,假设为expression = Expression<Func<TEntity, object>>
:
MemberExpression memberExpression;
switch (expression.Body.NodeType)
{
case ExpressionType.Convert:
memberExpression = ((UnaryExpression) expression.Body).Operand as MemberExpression;
break;
case ExpressionType.MemberAccess:
memberExpression = expression.Body as MemberExpression;
break;
}
var propInfo = memberExpression.Member as PropertyInfo;
然后只使用SetValue