Chapter 8. Code Contracts

This chapter will introduce you to code contracts. This is a very powerful technology and one that will enable you to secure your code from unnecessary errors. This is especially true when you are writing a class that is shared between several developers. Code contracts allow you to inspect and handle data passed to your method under contract. If the contract fails its validation, you can take decisive action within your method to handle this eventuality. This chapter will cover the following recipes:

  • Downloading, installing, and integrating code contracts into Visual Studio
  • Creating code contract preconditions
  • Creating code contract postconditions
  • Creating code contract invariant
  • Creating code contract Assert and Assume

Get C# Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.