Skip to content

Instantly share code, notes, and snippets.

@mikeobrien
Created June 13, 2011 16:27
Show Gist options
  • Save mikeobrien/1023113 to your computer and use it in GitHub Desktop.
Save mikeobrien/1023113 to your computer and use it in GitHub Desktop.
public static T ThrowIfNull<T>(this T target) where T : class
{
if (target == null) throw new NullReferenceException(
string.Format("Object reference of type '{0}' not set to an instance of an object.", typeof(T).FullName));
return target;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment