Open sandboxFocus

Class 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.

Namespace: Metalama.Patterns.Contracts
Assembly: Metalama.Patterns.Contracts.dll
Syntax
public class RangeAttribute : ContractBaseAttribute, IAspect<IParameter>, IEligible<IParameter>, IAspect<IFieldOrPropertyOrIndexer>, IEligible<IFieldOrPropertyOrIndexer>, IConditionallyInheritableAspect, IAspect, ICompileTimeSerializable, ITemplateProvider
Remarks
<p>Null values are accepted and do not throw an exception.

Error message can use additional argument {4} to refer to the minimum value used and {5} to refer to the maximum value used.

Constructors

Name Description
RangeAttribute(byte, sbyte, bool, bool)

Initializes a new instance of the RangeAttribute class specifying bounds of type byte.

RangeAttribute(double, double, bool, bool)

Initializes a new instance of the RangeAttribute class specifying bounds of type double.

RangeAttribute(short, short, bool, bool)

Initializes a new instance of the RangeAttribute class specifying bounds of type short.

RangeAttribute(int, int, bool, bool, int)

Initializes a new instance of the RangeAttribute class specifying bounds of type int.

RangeAttribute(long, long, bool, bool, int)

Initializes a new instance of the RangeAttribute class specifying bounds of type long.

RangeAttribute(float, float, bool, bool)

Initializes a new instance of the RangeAttribute class specifying bounds of type float.

RangeAttribute(ushort, ushort, bool, bool)

Initializes a new instance of the RangeAttribute class specifying bounds of type ushort.

RangeAttribute(uint, uint, bool, bool)

Initializes a new instance of the RangeAttribute class specifying bounds of type uint.

RangeAttribute(ulong, ulong, bool, bool)

Initializes a new instance of the RangeAttribute class specifying bounds of type ulong.

Properties

Name Description
Range

Gets the numeric range used for validation.

Methods

Name Description
BuildAspect(IAspectBuilder<IFieldOrPropertyOrIndexer>)
BuildAspect(IAspectBuilder<IParameter>)
BuildEligibility(IEligibilityBuilder<IFieldOrPropertyOrIndexer>)

Configures the eligibility of the aspect or attribute by defining rules that determine which declarations the aspect can be applied to.

BuildEligibility(IEligibilityBuilder<IParameter>)

Configures the eligibility of the aspect or attribute by defining rules that determine which declarations the aspect can be applied to.

OnContractViolated(dynamic?, NumericRange, ContractContext)

Template method called when the contract validation fails. Override to customize the error behavior.

Validate(dynamic?)

The template method that validates or normalizes the value of a field, property, indexer, or parameter.

Extension Methods

See Also