Skip to content

Instantly share code, notes, and snippets.

Created February 25, 2013 19:34
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
C# Preconditions
public class Preconditions
/// <summary>
/// Ensures that an object reference passed as a parameter to the calling method is not null.
/// </summary>
/// <param name="reference">an object reference</param>
/// <param name="errorMessage">the exception message to use if the check fails</param>
/// <returns>the non-null reference that was validated</returns>
/// <exception cref="NullReferenceException">if reference is null</exception>
public static T CheckNotNull<T>(T reference, string errorMessage)
if (reference == null)
throw new NullReferenceException(errorMessage);
return reference;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment