PostSharp6.4/API Reference/Post­Sharp.​Patterns.​Contracts Namespace

PostSharp.Patterns.Contracts Namespace

This namespace contains ready-made contracts that validate fields, properties and parameters at runtime.
Classes
  ClassDescription
Public classContractExceptionFactory
Base class for contract exception factories. Implements chain of responsibility between concrete exception factories.
Public classContractExceptionInfo
This class holds the information from which the ContractExceptionFactory should create the exception.
Public classContractLocalizedTextProvider
Base class for contract error messages providers.
Public classContractServices
This class provides services supporting Contract aspects. By adding your own classes to the ExceptionFactory chain, you can change the way the exceptions are created when a contract is broken. By plugging into the LocalizedTextProvider chain, you can change the way the exception messages are generated. See the documentation for the classes for more details: ContractLocalizedTextProvider, ContractExceptionFactory.
Public classCreditCardAttribute
Custom attribute that, when added to a field, property or parameter, throws an ArgumentException if the target is assigned a value that is not a valid credit card number. Null strings are accepted and do not throw an exception.
Public classDefaultContractExceptionFactory
Default implementation of ContractExceptionFactory.
Public classEmailAddressAttribute
Custom attribute that, when added to a field, property or parameter, throws an ArgumentException if the target is assigned a value that is not a valid email address. Null strings are accepted and do not throw an exception.
Public classEnumDataTypeAttribute
Custom attribute that, when added to a field, property or parameter, throws an ArgumentException if the target is assigned a value that is not a valid member of an enumeration.
Public classGreaterThanAttribute
Custom attribute that, when added to a field, property or parameter, throws an ArgumentOutOfRangeException if the target is assigned a value that is smaller than a given value.
Public classLessThanAttribute
Custom attribute that, when added to a field, property or parameter, throws an ArgumentOutOfRangeException if the target is assigned a value that is greater than a given value.
Public classLocationContractAttribute
Base class for other custom attributes in this namespace.
Public classNegativeAttribute
Custom attribute that, when added to a field, property or parameter, throws an ArgumentOutOfRangeException if the target is assigned a value greater than zero.
Public classNotEmptyAttribute
Custom attribute that, when added to a field, property or parameter, throws an ArgumentNullException if the target is assigned a null or empty value. The custom attributes can be added to locations of type String (where empty means zero characters) or ICollection, ICollection<T> (where empty means zero items).
Public classNotNullAttribute
Custom attribute that, when added to a field, property or parameter, throws an ArgumentNullException if the target is assigned a null value.
Public classPhoneAttribute
Custom attribute that, when added to a field, property or parameter, throws an ArgumentException if the target is assigned a value that is not a valid phone number. Null strings are accepted and do not throw an exception.
Public classPositiveAttribute
Custom attribute that, when added to a field, property or parameter, throws an ArgumentOutOfRangeException if the target is assigned a value smaller than zero.
Public classPostconditionFailedException
The exception that is thrown when a postcondition contract was not fulfilled by a method.
Public classRangeAttribute
Custom attribute that, when added to a field, property or parameter, throws an ArgumentOutOfRangeException if the target is assigned a value that is outside a given range.
Public classRegularExpressionAttribute
Custom attribute that, when added to a field, property or parameter, throws an ArgumentException if the target is assigned a value that does not match a given regular expression. Null strings are accepted and do not throw an exception.
Public classRequiredAttribute
Custom attribute that, when added to a field, property or parameter, throws:
Public classStrictlyGreaterThanAttribute
Custom attribute that, when added to a field, property or parameter, throws an ArgumentOutOfRangeException if the target is assigned a value that is smaller than or equal to a given value.
Public classStrictlyLessThanAttribute
Custom attribute that, when added to a field, property or parameter, throws an ArgumentOutOfRangeException if the target is assigned a value that is greater than or equal to a given value.
Public classStrictlyNegativeAttribute
Custom attribute that, when added to a field, property or parameter, throws an ArgumentOutOfRangeException if the target is assigned a value greater than or equal to zero.
Public classStrictlyPositiveAttribute
Custom attribute that, when added to a field, property or parameter, throws an ArgumentOutOfRangeException if the target is assigned a value smaller than or equal to zero.
Public classStrictRangeAttribute
Custom attribute that, when added to a field, property or parameter, throws an ArgumentOutOfRangeException if the target is assigned a value that is not strictly within the given range.
Public classStringLengthAttribute
Custom attribute that, when added to a field, property or parameter, throws an ArgumentException if the target is assigned a string of invalid length. Null strings are accepted and do not throw an exception.
Public classUrlAttribute
Custom attribute that, when added to a field, property or parameter, throws an ArgumentException if the target is assigned a value that is not a valid URL starting with http://, https:// or ftp://. Null strings are accepted and do not throw an exception.