Created
February 25, 2013 19:34
-
-
Save johnlcox/5032524 to your computer and use it in GitHub Desktop.
C# Preconditions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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