Protect your code from invalid inputs with custom attributes.
- Works consistently on fields, properties or parameters.
- Rich built-in contracts.
Defensive programming starts here.
Simple and Consistent
Apply to any code – Use contract attributes on any class at any location in your codebase, not only in ASP.NET MVC or XAML.
Fields, properties and parameters – Code Contracts are not limited to method parameters. Use them on fields, properties and parameters.
Inheritance – Applying Code Contracts to base classes and interfaces will enforce their rules on objects that inherit or implement these objects.
Rich built-in contracts – Validate for valid URLs, email addresses, positive numbers or not-null values and many more, right out of the box.
Extensible – Base classes provide you with a strong foundation on which to build custom Code Contracts. Create any validation that you need.