ThrowIfDefault

public static T ThrowIfDefault<T>(this T val, Func<Exception> exceptionFunc)
{
    //found here
    //http://www.extensionmethod.net/csharp/object/isdefaultfortype
    if(val.IsDefaultForType())
        throw exceptionFunc();
    return val;
}
Example:
var emailData = GetActiveEmailByName(emailName);

emailData.ThrowIfDefault(() => new InvalidOperationException("Unable to load email settings. Is the webconfig key 'EmailName' correct and the record active?"));

Description

Throws a given Exception if the given object is equal to the default value for the type

Details

Double click on the code to select all.

 

;