Skip to content

Instantly share code, notes, and snippets.

@JohnLudlow
Last active Jan 15, 2016
Embed
What would you like to do?
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