我有下面的函数,当我调用它时返回“Test” GetPropertyName<Model>(x => x.Test)
。
如何返回深度调用,例如:User.UserName。
我想看看User.UserName
我什么时候打电话GetPropertyName<Model>(x => x.User.FullName)
谢谢
public static string GetPropertyName<T>(Expression<Func<T, object>> expression)
{
var body = expression.Body as MemberExpression;
if (body == null)
{
body = ((UnaryExpression)expression.Body).Operand as MemberExpression;
}
if (body != null)
{
return body.Member.Name;
}
return null;
}
编辑 1
这是我的课:
public class Place : BaseEntity
{
public virtual User UserManager { get; set; }
}
public class User : BaseEntity
{
public virtual string FullName { get; set; }
}