我設法找到了一種方法,但它看起來更多的解決方法,馬克的版本更簡單。我會盡快接受馬克的回答。繼承人我的解決方法:
public class MemberModifier : ExpressionVisitor
{
public Expression Modify(Expression expression)
{
return Visit(expression);
}
protected override Expression VisitMember(MemberExpression node)
{
var t = typeof (DepartmentPaperConsumption);
var memberInfo = t.GetMember("TotalPages")[0];
return Expression.MakeMemberAccess(node.Expression, memberInfo);
}
}
,然後在代碼
Expression<Func<object>> exp =() => dto.TotalColorPrints;
var mod = new MemberModifier();
var modEx = mod.Modify(exp);
result.OrderByAlias((Expression<Func<object>>)modEx)
MemberModifier只有原始的原型,它應該是更通用的,不依賴於DepartmentConsumption,沒有硬編碼「總頁數」
你不介意張貼`OrderbyAlias`方法的簽名? – Ani 2011-01-27 12:52:55
如果它有幫助QueryOverOrderBuilder OrderByAlias(表達式>路徑) –
2011-01-27 13:25:56