Skip to content

Instantly share code, notes, and snippets.

@JohnLudlow
Last active January 15, 2016 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohnLudlow/1e434e91c98ef0ca1f71 to your computer and use it in GitHub Desktop.
Save JohnLudlow/1e434e91c98ef0ca1f71 to your computer and use it in GitHub Desktop.
Contracts
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