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

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

Methods

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

Configures the eligibility of the aspect or attribute. Implementations are not allowed to reference non-static members. Implementations must call the implementation of the base class if it exists.

BuildEligibility(IEligibilityBuilder<IParameter>)

Configures the eligibility of the aspect or attribute. Implementations are not allowed to reference non-static members. Implementations must call the implementation of the base class if it exists.

OnContractViolated(dynamic?, NumericRange, ContractContext)
Validate(dynamic?)

Extension Methods

See Also