I map properties using Expression<Func<TEntity, object>>
.
I've just needed to fetch property values from objects until know. 开发者_运维技巧How can I assign values using that expression?
try this, assuming 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;
then just use SetValue
精彩评论