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: PostSharp.Patterns.Contracts
Assembly: PostSharp.Patterns.Common.dll
Syntax
public class RangeAttribute : LocationContractAttribute, ILocationLevelAspect, IValidableAnnotation, IAspect
Remarks

Null values are accepted and do not throw an exception.

The error message is identified by RangeErrorMessage.

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

Constructors

Name Description
RangeAttribute(double, double)

Initializes a new instance of the RangeAttribute class and specifies floating-point bounds.

RangeAttribute(long, long)

Initializes a new instance of the RangeAttribute class and specifies integer bounds.

RangeAttribute(ulong, ulong)

Initializes a new instance of the RangeAttribute class and specifies ulong bounds.

Properties

Name Description
DisplayMaxValue

Gets the maximum value to be used when generating the error message, typically in the implementation of GetErrorMessageArguments().

DisplayMinValue

Gets the minimum value to be used when generating the error message, typically in the implementation of GetErrorMessageArguments().

Methods

Name Description
CompileTimeValidate(object)

Method invoked at build time to ensure that the aspect has been applied to the right target.

CreateException(object, string, LocationKind, LocationValidationContext)
GetErrorMessage()

Gets the unformatted error message as defined by the instance.

GetErrorMessageArguments()

Gets the values of the additional arguments for the error message associated with a particular instance of LocationContractAttribute. These arguments can be referenced from the error message string by {4}, {5}, and so on.

ValidateValueDynamic(object, string, LocationKind, LocationValidationContext)

Validates a weakly-typed (boxed) value, typically the value of a dependency property or an attached property.