这是表达式树的正确用法吗?
Would this be the correct usage of an expression tree?
我有这两个相似的方法,我觉得它们可以用传递大于或小于符号的表达式树代替
public List<IAccount> IsGreater(DateTime someDate)
{
return AccountList.Where(a =>
a.AccountDate >= someDate && a.SomeBoolMethod() && a.SomeOtherBoolMethod())
}
public List<IAccount> IsLess(DateTime someDate)
{
return AccountList.Where(a =>
a.AccountDate < someDate && a.SomeBoolMethod() && a.SomeOtherBoolMethod())
}
从我读到的关于表达式树的内容来看,我觉得这样的东西可能是有序的
Expression<Func<DateTime, ExpressionType, DateTime, bool, bool, bool, List<IAccount>>>
expression = (a, b, c, d, e, f) =>
{
// not sure how to do this here
}
我在正确的街区吗?
为什么要构建整个表达式树?就目前的问题来说,你直接比较就可以了。
public List<IAccount> FilterAccounts( Predicate<IAccount> condition )
{
return AccountList.Where(a => condition(a) && a.SomeBoolMethod() && a.SomeOtherBoolMethod() )
}
public List<IAccount> IsGreater(DateTime someDate)
{
return FilterAccounts( a => a.AccountDate >= someDate );
}
public List<IAccount> IsLess(DateTime someDate)
{
return FilterAccounts( a => a.AccountDate < someDate );
}
我有这两个相似的方法,我觉得它们可以用传递大于或小于符号的表达式树代替
public List<IAccount> IsGreater(DateTime someDate)
{
return AccountList.Where(a =>
a.AccountDate >= someDate && a.SomeBoolMethod() && a.SomeOtherBoolMethod())
}
public List<IAccount> IsLess(DateTime someDate)
{
return AccountList.Where(a =>
a.AccountDate < someDate && a.SomeBoolMethod() && a.SomeOtherBoolMethod())
}
从我读到的关于表达式树的内容来看,我觉得这样的东西可能是有序的
Expression<Func<DateTime, ExpressionType, DateTime, bool, bool, bool, List<IAccount>>>
expression = (a, b, c, d, e, f) =>
{
// not sure how to do this here
}
我在正确的街区吗?
为什么要构建整个表达式树?就目前的问题来说,你直接比较就可以了。
public List<IAccount> FilterAccounts( Predicate<IAccount> condition )
{
return AccountList.Where(a => condition(a) && a.SomeBoolMethod() && a.SomeOtherBoolMethod() )
}
public List<IAccount> IsGreater(DateTime someDate)
{
return FilterAccounts( a => a.AccountDate >= someDate );
}
public List<IAccount> IsLess(DateTime someDate)
{
return FilterAccounts( a => a.AccountDate < someDate );
}