Files
kami_itunes_june/AppleBatch_June/PredicateBuilder.cs
2024-07-22 00:43:14 +08:00

32 lines
952 B
C#

using System;
using System.Linq;
using System.Linq.Expressions;
namespace AppleBatch_June
{
public static class PredicateBuilder
{
public static Expression<Func<T, bool>> True<T>()
{
return (T f) => true;
}
public static Expression<Func<T, bool>> False<T>()
{
return (T f) => false;
}
public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> expr1, Expression<Func<T, bool>> expr2)
{
InvocationExpression right = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());
return Expression.Lambda<Func<T, bool>>(Expression.Or(expr1.Body, right), expr1.Parameters);
}
public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> expr1, Expression<Func<T, bool>> expr2)
{
InvocationExpression right = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());
return Expression.Lambda<Func<T, bool>>(Expression.And(expr1.Body, right), expr1.Parameters);
}
}
}