Open sandboxFocus

Namespace Metalama.Patterns.Contracts

Classes

ContractBaseAttribute

A base class for all contracts defined in this library.

ContractConfigurationExtensions

Fabric extension methods to configure the Metalama.Patterns.Contracts namespace.

ContractContext

Represents the context in which a ContractBaseAttribute is used, i.e. its target declaration and Options.

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. You can configure these options using the ConfigureContracts(IAspectReceiver<ICompilation>, ContractOptions) method.

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 bound. The behavior when the target is exactly assigned to the bound depends on the DefaultInequalityStrictness option. If this option is not specified, a warning is reported.

GreaterThanOrEqualAttribute

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 bound. The behavior when the target is exactly assigned to the bound depends on the DefaultInequalityStrictness option. If this option is not specified, a warning is reported.

LessThanOrEqualAttribute

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. The behavior when the target is assigned to zero depends on the DefaultInequalityStrictness option. If this option is not specified, a warning is reported.

NonNegativeAttribute

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

NonPositiveAttribute

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 string (where empty means zero characters), or ICollection, ICollection<T>, IReadOnlyCollection<T>, arrays or ImmutableArray<T> (where empty means zero items). Null references or default ImmutableArray<T> 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. The behavior when the target is assigned to zero depends on the DefaultInequalityStrictness option. If this option is not specified, a warning is reported.

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:

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.

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.

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.

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.

Structs

SuspendInvariantsCookie

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

Enums

InequalityStrictness

Enumerates the meanings of inequalities of unspecified strictness such as GreaterThanAttribute, LessThanAttribute, PositiveAttribute and NegativeAttribute.