请帮助我从这个 lambda 表达式构建树表达式
x => (DateTime)x[key].Date
x 的 SPListItem 类型。类 Expression 包含不同的方法 - Expression.Property(...), Expression.MemberInit(...) -我不明白如何使用它。在不同的情况下使用什么方法。
我花了三天时间解决这个任务,但没有运气。
更新。一些细节:我正在使用 SharePoint,我需要按某些字段对 SPListItemCollection 进行排序。对于 DateTime 字段,它必须仅按日期排序。我不能用 CAML 查询来做到这一点,所以我可以使用 linq。
OrderBy(item => (DateTime)item[fieldName].Date)
完美运行。但是可以通过许多参数进行排序。我尝试在 Expression 类的帮助下创建动态 linq 查询。如果我的 lambda 表达式是,例如,x=>x.property,它会很简单
var pe = Expression.Parameter(typeof(x));
var property1 = typeof(x).GetProperty(property);
但是我如何为 (item => (DateTime)item[fieldName].Date) 做到这一点?