/// <summary> /// Filter the current sequence for elements that match a given predicate. /// </summary> /// <typeparam name="T">The type of the items in the sequence.</typeparam> /// <param name="source">The current sequence of elements.</param> /// <param name="predicate"> /// A condition to filter the sequence by. /// </param> /// <returns> /// A sequence of elements filtered by the given predicate. /// </returns> public static IEnumerable <T> Where <T>(this IEnumerable <T> source, IQualify <T> predicate) { foreach (var x in source) { if (predicate.Qualify(x)) { yield return(x); } } }
/// <summary> /// Add a disjunctive (OR) qualifier to the current qualifier. /// </summary> /// <typeparam name="T">The type of the object to qualify.</typeparam> /// <param name="current">The current qualifier.</param> /// <param name="qualifier"> /// A delegate qualifier to serve as the right-hand side of the operation. /// </param> /// <returns> /// A disjunctive qualifier consisting of the current qualifier as the left-hand side /// of the operation and an additional qualifier as the right-hand side. /// </returns> public static IQualify <T> Or <T>(this IQualify <T> current, Qualifier <T> qualifier) { return(new DisjunctiveQualifier <T>(current.Qualify, qualifier)); }
/// <summary> /// Negate the current qualifier. /// </summary> /// <typeparam name="T">The type of the object to qualify.</typeparam> /// <param name="current">The current qualifier.</param> /// <returns>A negation of the current qualifier.</returns> public static IQualify <T> Negate <T>(this IQualify <T> current) { return(new NegatedQualifier <T>(current.Qualify)); }
/// <summary> /// Add a conjunctive (AND) qualifier to the current qualifier. /// </summary> /// <typeparam name="T">The type of the object to qualify.</typeparam> /// <param name="current">The current qualifier.</param> /// <param name="qualifier">A qualifier to serve as the right-hand side of the operation.</param> /// <returns> /// A conjunctive qualifier consisting of the current qualifier as the left-hand side /// of the operation and an additional qualifier as the right-hand side. /// </returns> public static IQualify <T> And <T>(this IQualify <T> current, IQualify <T> qualifier) { return(new ConjunctiveQualifier <T>(current.Qualify, qualifier.Qualify)); }
/// <summary> /// Add a disjunctive (OR) qualifier to the current qualifier. /// </summary> /// <typeparam name="T">The type of the object to qualify.</typeparam> /// <param name="current">The current qualifier.</param> /// <param name="qualifier">A qualifier to serve as the right-hand side of the operation.</param> /// <returns> /// A disjunctive qualifier consisting of the current qualifier as the left-hand side /// of the operation and an additional qualifier as the right-hand side. /// </returns> public static Qualifier <T> Or <T>(this Qualifier <T> current, IQualify <T> qualifier) { return(new DisjunctiveQualifier <T>(current, qualifier.Qualify).Qualify); }