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


Throw's a given exception is a given predicate is True


public static T ThrowIf<T>(this T val, Func<T, bool> predicate, Func<Exception> exceptionFunc)
    if (predicate(val))
        throw exceptionFunc();
    return val;


int? tempId = Submit();

tempId.ThrowIf(i=>!i.HasValue,()=>ServiceFault<FatalExceptionFault>.FaultFor("Unable to submit to Temp Database!"));

Author: Adam

Submitted on: 18 jul 2013

Language: C#

Type: System.Object

Views: 5481