ThrowIfAny

public static IEnumerable<T> ThrowIfAny<T>(this IEnumerable<T> values, Func<T, bool> predicate, Func<Exception> exceptionFunc)
{
    if (values.Any(val => predicate(val)))
        throw exceptionFunc();
    return values;
}
Example:
categories.ThrowIfAny(c => c == CategoryTypes.Unknown, () => new Exception("The note category must be set."));

Description

Throws a given exception is any value in a set passes a given predicate

Details

Double click on the code to select all.

 

;