Open sandboxFocus

Class 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. Null strings are accepted and do not throw an exception.

Namespace: PostSharp.Patterns.Contracts
Assembly: PostSharp.Patterns.Common.dll
Syntax
public class RegularExpressionAttribute : LocationContractAttribute, ILocationLevelAspect, IAspect
Remarks

The error message is identified by RegularExpressionErrorMessage.

The error message can use the additional argument {4} to refer to the regular expression used.

Constructors

Name Description
RegularExpressionAttribute(string)

Initializes a new instance of the RegularExpressionAttribute class.

RegularExpressionAttribute(string, RegexOptions)

Initializes a new instance of the RegularExpressionAttribute class and specifies options.

Methods

Name Description
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.