/// <summary>
/// 获取表达式属性名称
/// </summary>
/// <typeparam name="TModel"></typeparam>
/// <typeparam name="TValue"></typeparam>
/// <param name="expr"></param>
/// <returns></returns>
private string GetExpressionMemberName<TModel, TValue>(System.Linq.Expressions.Expression<Func<TModel, TValue>> expr)
{
var unary = expr.Body as UnaryExpression;
MemberExpression member;
if (unary != null)
{
member = unary.Operand as MemberExpression;
}
else
{
member = expr.Body as MemberExpression;
}
if (member == null)
{
throw new Exception("表达式解析异常");
}
var itemName = member.Member.Name; //属性名
return itemName;
}