MetalamaAPI documentationPatterns APIMetalama.​Patterns.​Contracts
Open sandboxFocus

Metalama.Patterns.Contracts Namespace

Classes

ContractBaseAttribute

A base class for all contracts defined in this library.

ContractExtensions

Fabric extension methods allowing to add NotNullAttribute contracts in bulk and to access options.

ContractHelpers

Runtime helper methods for RangeAttribute.

ContractOptions

Options for all aspects of the Metalama.Patterns.Contracts namespace.

ContractTemplates

Provides default implementations for the code templates used by code contract aspects (derived from ContractBaseAttribute). This class can be derived and templates can be overridden. To register the new template implementations, use the Templates contract options.

CreditCardAttribute

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. If the target is a nullable type, If the target is a nullable type, null strings are accepted and do not throw an exception.

DoNotCheckInvariantsAttribute

Custom attribute that, when applied to a method, means that invariants should not be checked when this method completes.

EmailAttribute

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. If the target is a nullable type, null strings are accepted and do not throw an exception.

EnumDataTypeAttribute

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.

EnumDataTypeAttributeHelper

GreaterThanAttribute

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.

InvariantAttribute

Aspect that, when added to a parameterless void method, causes this method to be invoked after each property setter or method (but not property getters), except those annotated with DoNotCheckInvariantsAttribute. The target method must check any relevant condition and throw throw InvariantViolationException in case of violation.

InvariantSuspensionCounter

A class used by the InvariantAttribute aspect to count the number of times the SuspendInvariants method has been invoked.

InvariantViolationException

An exception that should be thrown by the target methods of the InvariantAttribute aspect.

LessThanAttribute

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.

NegativeAttribute

Custom attribute that, when added to a field, property or parameter, throws an ArgumentOutOfRangeException if the target is assigned a value greater than zero.

NotEmptyAttribute

Custom attribute that, when added to a field, property or parameter, throws an ArgumentException if the target is assigned an empty value. The custom attributes can be added to locations of type System.String (where empty means zero characters), or ICollection, System.Collections.Generic.ICollection<>, System.Collections.Generic.IReadOnlyCollection<>, arrays or System.Collections.Immutable.ImmutableArray<> (where empty means zero items). Null references or default System.Collections.Immutable.ImmutableArray<> instances are accepted and do not throw an exception.

NotNullAttribute

Custom attribute that, when added to a field, property or parameter, throws an ArgumentNullException if the target is assigned a null value.

PhoneAttribute

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. If the target is a nullable type, null strings are accepted and do not throw an exception.

PositiveAttribute

Custom attribute that, when added to a field, property or parameter, throws an ArgumentOutOfRangeException if the target is assigned a value smaller than zero.

PostconditionViolationException

The exception that is thrown when a postcondition contract was not fulfilled by a method.

RangeAttribute

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.

RegularExpressionAttribute

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. If the target is a nullable type, null strings are accepted and do not throw an exception.

RegularExpressionBaseAttribute

The base class of contracts that are based on custom attributes.

RequiredAttribute

Custom attribute that, when added to a field, property or parameter, throws:

StrictlyGreaterThanAttribute

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.

StrictlyLessThanAttribute

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.

StrictlyNegativeAttribute

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.

StrictlyPositiveAttribute

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.

StrictRangeAttribute

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.

StringLengthAttribute

Custom attribute that, when added to a field, property or parameter, throws an ArgumentException if the target is assigned a string of invalid length. If the target is a nullable type, If the target is a nullable type, null strings are accepted and do not throw an exception.

SuspendInvariantsAttribute

Aspect that, when applied to a method or accessor, suspends the execution of invariants for the object while this method is executing. All threads and execution contexts are affected. The feature must be enabled through the IsInvariantSuspensionSupported contract option.

SuspendInvariantsCookie

A disposable cookie returned by the SuspendInvariants method generated by the InvariantAttribute aspect.

UrlAttribute

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://. If the target is a nullable type, If the target is a nullable type, null strings are accepted and do not throw an exception.