using System;
using System.Linq;
using System.Linq.Expressions;
namespace CK.SCP.Utils
{
public static class PredicateBuilder
{
///
/// 机关函数应用True时:单个AND有效,多个AND有效;单个OR无效,多个OR无效;混应时写在AND后的OR有效
///
///
///
public static Expression> True() { return f => true; }
///
/// 机关函数应用False时:单个AND无效,多个AND无效;单个OR有效,多个OR有效;混应时写在OR后面的AND有效
///
///
///
public static Expression> False() { return f => false; }
public static Expression> Or(this Expression> expr1,
Expression> expr2)
{
var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast());
return Expression.Lambda>
(Expression.Or(expr1.Body, invokedExpr), expr1.Parameters);
}
public static Expression> And(this Expression> expr1,
Expression> expr2)
{
var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast());
return Expression.Lambda>
(Expression.And(expr1.Body, invokedExpr), expr1.Parameters);
}
}
}