0
public class Job
{
public string Name { get; set; }
public int Salary { get; set; }
}
public class Employee
{
public string Name { get; set; }
public Job Job { get; set; }
}
如果我想創建的成員訪問Employee.Name這個表達式樹是我做的:深度的成員訪問表達式樹> 1
var param = Expression.Parameter(type, "x");
var memberAccess = Expression.PropertyOrField(param, memberName);
return Expression.Lambda<Func<TModel, TMember>>(memberAccess, param);
什麼是相當於這爲一個成員訪問Employee.Job.Salary?
我試過使用我創建的memberAccess並在其上創建另一個memberAccess:Expression.PropertyOrField(baseMemberAccess,memberName),它沒有工作,它試圖找到基本成員內的memberName訪問Func <> –