mirror of
https://git.oceanpay.cc/danial/kami_itunes_june.git
synced 2025-12-18 22:31:24 +00:00
32 lines
952 B
C#
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);
|
|
}
|
|
}
|
|
}
|