The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
ContractClassAttribute Class
Specifies that a separate type contains the code contracts for this type.
Namespace: System.Diagnostics.Contracts
Assembly: mscorlib (in mscorlib.dll)
The ContractClassAttribute type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | ContractClassAttribute | Initializes a new instance of the ContractClassAttribute class. |
| Name | Description | |
|---|---|---|
![]() | TypeContainingContracts | Gets the type that contains the code contracts for this type. |
| Name | Description | |
|---|---|---|
![]() | Equals | Infrastructure. Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Returns the hash code for this instance. (Inherited from Attribute.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | Match | When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
The following example shows how to use the ContractClassAttribute attribute to specify that the contracts for the IArray interface are contained in the IArrayContracts class.
using System; using System.Diagnostics.Contracts; // An IArray is an ordered collection of objects. [ContractClass(typeof(IArrayContract))] public interface IArray { // The Item property provides methods to read and edit entries in the array. Object this[int index] { get; set; } int Count { get; } // Adds an item to the list. // The return value is the position the new element was inserted in. int Add(Object value); // Removes all items from the list. void Clear(); // Inserts value into the array at position index. // index must be non-negative and less than or equal to the // number of elements in the array. If index equals the number // of items in the array, then value is appended to the end. void Insert(int index, Object value); // Removes the item at position index. void RemoveAt(int index); } [ContractClassFor(typeof(IArray))] internal abstract class IArrayContract : IArray { int IArray.Add(Object value) { // Returns the index in which an item was inserted. Contract.Ensures(Contract.Result<int>() >= -1); Contract.Ensures(Contract.Result<int>() < ((IArray)this).Count); return default(int); } Object IArray.this[int index] { get { Contract.Requires(index >= 0); Contract.Requires(index < ((IArray)this).Count); return default(int); } set { Contract.Requires(index >= 0); Contract.Requires(index < ((IArray)this).Count); } } public int Count { get { Contract.Requires(Count >= 0); Contract.Requires(Count < ((IArray)this).Count); return default(int); } } void IArray.Clear() { Contract.Ensures(((IArray)this).Count == 0); } void IArray.Insert(int index, Object value) { Contract.Requires(index >= 0); Contract.Requires(index <= ((IArray)this).Count); // For inserting immediately after the end. Contract.Ensures(((IArray)this).Count == Contract.OldValue(((IArray)this).Count) + 1); } void IArray.RemoveAt(int index) { Contract.Requires(index >= 0); Contract.Requires(index < ((IArray)this).Count); Contract.Ensures(((IArray)this).Count == Contract.OldValue(((IArray)this).Count) - 1); } }
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.
Community Additions
Show:


