Howdy,
The Code Contracts User Manual holds (besides detailed information about Code Contracts’ usage, advantages and drawbacks) a few nice lists of Code Snippets that ship with the Code Contracts and will ease your life. Find below the list of available Code Snippets for the C# language, as exactly taken from the User Manual (January 12th, 2010):
| cr | Contract.Requires(…); |
| ce | Contract.Ensures(…); |
| ci | Contract.Invariant(…); |
| crr | Contract.Result<…>() |
| co | Contract.OldValue(…) |
| cim | [ContractInvariantMethod]
private ObjectInvariant() { Contract.Invariant(…); } |
| crn | Contract.Requires(… != null); |
| cen | Contract.Ensures(Contracts.Result<…>() != null); |
| crsn | Contract.Requires( !String.IsNullOrEmpty(…) ); |
| cesn | Contract.Ensures( !String.IsNullOrEmpty(Contracts.Result<string>()) ); |
| cca | Contract.Assert(…); |
| cam | Contract.Assume(…); |
| cre | Contract.Requires<E>(…); |
| cren | Contract.Requires<ArgumentNullException>(… != null); |
| cresn | Contract.Requires<ArgumentException>( !String.IsNullOrEmpty(…) ); |
| cintf | expands to an interface template and associated contract class |
If you plan to use Code Contracts effectively, this list comes in very handy. I hope it’s of use for you. In the Code Contracts User Manual, you can find a similar list also for Visual Basic.
Best regards,
Martin


Very helpful, thanks for this!
Por que no:)