Code Contracts

suggest change

Versions

[{“Name”:“4.0”,“GroupName”:null},{“Name”:“5.0”,“GroupName”:null},{“Name”:“6.0”,“GroupName”:null},{“Name”:“7.0”,“GroupName”:null}]

Syntax

  1. Contract.Requires(Condition,userMessage)
Contract.Requires<T>(Condition,userMessage)

Contract.Result<T>

Contract.Ensures() 

Contract.Invariants()

Remarks

.NET supports the Design by Contract idea via its Contracts class found in the System.Diagnostics namespace and introduced in .NET 4.0. Code Contracts API includes classes for static and runtime checks of code and allows you to define preconditions, postconditions, and invariants within a method. The preconditions specify the conditions the parameters must fulfill before a method can execute, postconditions that are verified upon completion of a method, and the invariants define the conditions that do not change during the execution of a method.

Why are Code Contracts needed?

Tracking issues of an application when your application is running, is one the foremost concerns of all the developers and administrators. Tracking can be performed in many ways. For example -

Code Contracts uses a different approach for tracking and managing issues within an application. Instead of validating everything that is returned from a method call, Code Contracts with the help of preconditions, postconditions, and invariants on methods, ensure that everything entering and leaving your methods are correct.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Code Contracts:
* Code Contracts

Table Of Contents
17 Regex
19 Arrays
21 Enum
22 Tuples
24 GUID
27 Looping
36 Casting
46 Methods
88 Events
92 Structs
104 Indexer
106 Stream
107 Timers
109 Threading
127 Caching
128 Code Contracts
135 Pointers
147 C# Script