namespace Strata.SqlTools.Rules.Rule.Expression;
///
/// Represents an ANY expression that checks if any element in a collection satisfies a condition.
///
public class Any : BoolExpr
{
///
/// Gets the collection property being evaluated.
///
public CollectionProperty CollectionProperty { get; }
///
/// Gets the BoolExpr expression that defines the condition to check.
///
public BoolExpr BoolExpr { get; }
///
/// Gets the parameter used in the predicate expression.
///
public Parameter PredicateParameter { get; }
///
/// Initializes a new instance of the class with a function.
///
/// The collection property to evaluate.
/// A function that defines the condition to check for each element.
public Any(CollectionProperty collectionProperty, Func func)
{
CollectionProperty = collectionProperty;
PredicateParameter = new Parameter("p");
BoolExpr = func(PredicateParameter);
}
///
/// Initializes a new instance of the class with a BoolExpr expression.
///
/// The collection property to evaluate.
/// The BoolExpr expression defining the condition.
public Any(CollectionProperty collectionProperty, BoolExpr boolExpr)
: this(collectionProperty, boolExpr, new Parameter("p"))
{
}
///
/// Initializes a new instance of the class.
///
/// The collection property to evaluate.
/// The BoolExpr expression defining the condition.
/// The parameter used in the predicate expression.
public Any(CollectionProperty collectionProperty, BoolExpr boolExpr, Parameter predicateParameter)
{
CollectionProperty = collectionProperty;
BoolExpr = boolExpr;
PredicateParameter = predicateParameter;
}
///
public override T Accept(IVisitor visitor) => visitor.VisitAny(this);
}