PostSharpAPI ReferencePost­Sharp.​Patterns.​ContractsRange­Attribute
Open sandboxFocus

RangeAttribute Class

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
[HasConstraint]
public class RangeAttribute : LocationContractAttribute, ILocationLevelAspect, IValidableAnnotation, IAspect
Remarks

Null values are accepted and do not throw an exception.

Error message is identified by RangeErrorMessage.

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(Double, Double)

Initializes a new GreaterThanAttribute and specify a floating-point bound.

RangeAttribute(Int64, Int64)

Initializes a new GreaterThanAttribute and specify an integer bound.

RangeAttribute(UInt64, UInt64)

Initializes a new GreaterThanAttribute and specify a UInt64 bound.

Properties

Name Description
DisplayMaxValue

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

DisplayMinValue

Gets the minimal 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 unformatted error message as defined by the instance.

GetErrorMessageArguments()

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

ValidateValue(Byte, String, LocationKind, LocationValidationContext)
ValidateValue(Decimal, String, LocationKind, LocationValidationContext)
ValidateValue(Double, String, LocationKind, LocationValidationContext)
ValidateValue(Int16, String, LocationKind, LocationValidationContext)
ValidateValue(Int64, String, LocationKind, LocationValidationContext)
ValidateValue(Nullable<Byte>, String, LocationKind, LocationValidationContext)
ValidateValue(Nullable<Decimal>, String, LocationKind, LocationValidationContext)
ValidateValue(Nullable<Double>, String, LocationKind, LocationValidationContext)
ValidateValue(Nullable<Int16>, String, LocationKind, LocationValidationContext)
ValidateValue(Nullable<Int32>, String, LocationKind, LocationValidationContext)
ValidateValue(Nullable<Int64>, String, LocationKind, LocationValidationContext)
ValidateValue(Nullable<SByte>, String, LocationKind, LocationValidationContext)
ValidateValue(Nullable<Single>, String, LocationKind, LocationValidationContext)
ValidateValue(Nullable<UInt16>, String, LocationKind, LocationValidationContext)
ValidateValue(Nullable<UInt32>, String, LocationKind, LocationValidationContext)
ValidateValue(Nullable<UInt64>, String, LocationKind, LocationValidationContext)
ValidateValue(SByte, String, LocationKind, LocationValidationContext)
ValidateValue(Single, String, LocationKind, LocationValidationContext)
ValidateValue(UInt16, String, LocationKind, LocationValidationContext)
ValidateValue(UInt32, String, LocationKind, LocationValidationContext)
ValidateValue(UInt64, String, LocationKind, LocationValidationContext)
ValidateValueDynamic(Object, String, LocationKind, LocationValidationContext)

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

ValidateValueInt(Int32, String, LocationKind, LocationValidationContext)