PostSharp Model

Code Contracts

Protect your code from invalid inputs with custom attributes.

  • Works consistently on fields, properties or parameters.
  • Rich built-in contracts.
  • Extensible.

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.

Tailored Validation

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.

Key Facts

Supported Platforms

.NET Framework 4.0, 4.5

Windows Phone 8, 8.1

Windows Store 8, 8.1