Last active
January 15, 2016 16:15
-
-
Save JohnLudlow/1e434e91c98ef0ca1f71 to your computer and use it in GitHub Desktop.
Contracts
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 static class Contract | |
{ | |
public static void Requires(Expression<Func<bool>> assertion) | |
{ | |
if(!assertion.Compile()()) | |
{ | |
throw new ContractRequirementException(string.Format("Expression {0} evaluated to false", assertion.ToString())); | |
} | |
} | |
public static void Ensures(Expression<Func<bool>> assertion) | |
{ | |
if (!assertion.Compile()()) | |
{ | |
throw new ContractPromiseException(string.Format("Expression {0} evaluated to false", assertion.ToString())); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment