Skip to content

Instantly share code, notes, and snippets.

@rrreese
Created November 18, 2012 11:08
Show Gist options
  • Save rrreese/4104588 to your computer and use it in GitHub Desktop.
Save rrreese/4104588 to your computer and use it in GitHub Desktop.
.NET Code Contracts
public static int Divide(int number, int divisor)
{
if (divisor == 0) throw new Exception();
public static int Divide(int number, int divisor)
{
Contract.Requires(divisor != 0);
public static double Divide(int number, int divisor)
{
Contract.Requires(divisor > 0);
return number / divisor;
}
Divide(1, 2);
Divide(1, 0);
public static void TestCodeContract(int value)
{
TestLimits(105);
TestLimits(95);
TestLimits(115);
}
public static void TestLimits(int i)
{
Contract.Requires(i > 100);
Contract.Requires(i < 110);
//Do Something
}
public static void TestCodeContract(int value)
{
TestLimits(value);
}
public static void TestCodeContract(int value)
{
if(value > 100 && value < 110)
TestLimits(value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment