ExtensionMethod.NET Home of 876 C#, Visual Basic, F# and Javascript extension methods


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


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;


categories.ThrowIfAny(c => c == CategoryTypes.Unknown, () => new Exception("The note category must be set."));

Author: Adam

Submitted on: 18 jul 2013

Language: C#

Type: System.Collection.Generic.IEnumerable<T>

Views: 4636