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.
ContractClassForAttribute Constructor (Type^)
.NET Framework (current version)
Initializes a new instance of the ContractClassForAttribute class, specifying the type the current class is a contract for.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- typeContractsAreFor
-
Type:
System::Type^
The type the current class is a contract for.
The following example shows how to use the ContractClassAttribute constructor to specify that the contracts in the type apply to the IArray interface. This code example is part of a larger example provided for the ContractClassAttribute class.
[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); } }
Universal Windows Platform
Available since 8
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 4.0
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1
Available since 8
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 4.0
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1
Show: