Course info
Jul 17, 2012
1h 51m

Code Contracts provide a way for developers to express coding assumptions in .NET libraries and applications, facilitating the delivery of more reliable code that is easier to understand and maintain. In this course, we will cover the basics of Code Contracts, including how to enforce preconditions, guarantee postconditions, and define invariants. We will also cover some advanced techniques available to the Code Contracts library, including interface contracts and quantifiers. By the end of this course, you should know enough to get started using Code Contracts, and have a good understanding of the capabilities of the library.

About the author
About the author

John Sonmez is the founder of Simple Programmer (, where he tirelessly pursues his vision of transforming complex issues into simple solutions

More from the author
Beginning Lua
2h 50m
Dec 2, 2013
Beginning HTML 5 Game Development With Quintus
2h 52m
Oct 25, 2013
Beginning HTML5 Apps For Firefox OS
2h 20m
Oct 17, 2013
More courses by John Sonmez
Section Introduction Transcripts
Section Introduction Transcripts

Code Contracts Overview
Hi, this is John Sonmez from Pluralsight and in this module we are going to be covering Code Contracts and we're just going to be talking a little bit about what Code Contracts are so we can understand why we would want to use them in our code. We're going to see a little bit about how they work at a very high level. And then we're going to see how to install Code Contracts into Visual Studio. It's not something that comes with Visual Studio. So we'll need to do an installation and get that so that we can use Code Contracts in the upcoming modules.

Basic Usage
Hi. This is John Sonmez from Pluralsight, and in this module, we are going to be going over the basic usage of code contracts. We are going to start off by looking at preconditions, and as we have said in the previous module, preconditions are basically conditions that we set up, that are required for our method to be used. So we're going to see how to set those up in a couple of different ways. Then we're going to go over postconditions, and there's a couple of things that we can do that are interesting with postconditions. So we're going to look at each one of those examples and we are going to see how to set up postconditions.

Digging Deeper
Hi this is John Sonmez from Pluralsight and in this module on Code Contracts, we're going to be actually be diving deeper into code contracts. So we're going to get into some of the more advanced topics. We're going to look at some things like object invariants so we're going to see how to use this inside of our code in order to make it so that, we have some constants and some rules that we check to make sure that our classes are always in the condition that we expect. We're going to see how to actually set up auto properties. Up to this point, we've been able to set up pre and post conditions but we haven't dealt with auto properties. And then we're going to look at some things like assert and assume and how to use those in our code. And then some quantifiers such as, for all and exist, so that we can actually make our constraints a little bit more powerful.

Hi, this is John Sonmez from Pluralsight. And welcome to the module on Advanced Techniques with Code Contracts. In this module, we are going to really get into some of the more advancing that you can do. We've already talked about preconditions and post condition and invariants and we've seen how to do some of the basic cases of using code contracts in our code. So, we've already covered most of what there is for, at least a runtime checking of code contracts. But in this module, we're going to get a little bit deeper. We're going to look at somethings like inheritance and we're going to get into static analysis. And we're not going to go too far into this. It is one of those fairly complex things that require perhaps even a whole course to really understand what's going on with the static analysis, but we're going to see how to set it up in the basic usage. And I'm going to refer you to another Pluralsight course that actually covers everything you really need to know to use static contracts.