Throw's a given exception is a given predicate is True
Source
public static T ThrowIf<T>(this T val, Func<T, bool> predicate, Func<Exception> exceptionFunc)
{
if (predicate(val))
throw exceptionFunc();
return val;
}
Example
int? tempId = Submit();
tempId.ThrowIf(i=>!i.HasValue,()=>ServiceFault<FatalExceptionFault>.FaultFor("Unable to submit to Temp Database!"));