ContractClassForAttribute Class
Specifies that a class is a contract for a type.
Assembly: mscorlib (in mscorlib.dll)
| Name | Description | |
|---|---|---|
![]() | ContractClassForAttribute(Type) | Initializes a new instance of the ContractClassForAttribute class, specifying the type the current class is a contract for. |
| Name | Description | |
|---|---|---|
![]() | TypeContractsAreFor | Gets the type that this code contract applies to. |
![]() | TypeId |
| Name | Description | |
|---|---|---|
![]() | Equals(Object) | This API supports the product infrastructure and is not intended to be used directly from your code. Returns a value that indicates whether this instance is equal to a specified object.(Inherited from Attribute.) |
![]() | GetHashCode() | Returns the hash code for this instance.(Inherited from Attribute.) |
![]() | GetType() | |
![]() | IsDefaultAttribute() | When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.(Inherited from Attribute.) |
![]() | Match(Object) | When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.(Inherited from Attribute.) |
![]() | ToString() | Returns a string that represents the current object.(Inherited from Object.) |
| Name | Description | |
|---|---|---|
![]() ![]() | _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) | Maps a set of names to a corresponding set of dispatch identifiers.(Inherited from Attribute.) |
![]() ![]() | _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) | Retrieves the type information for an object, which can be used to get the type information for an interface.(Inherited from Attribute.) |
![]() ![]() | _Attribute.GetTypeInfoCount(UInt32) | Retrieves the number of type information interfaces that an object provides (either 0 or 1).(Inherited from Attribute.) |
![]() ![]() | _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) | Provides access to properties and methods exposed by an object.(Inherited from Attribute.) |
Types that are marked with this attribute represent a code contract for another type. The type that the contract applies to is specified in the constructor.
The following example shows how to use the ContractClassForAttribute attribute to specify the contracts for another type. 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); } }
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
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.



