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. If the target is a nullable type, null strings are accepted and do not throw an exception.
Inheritance
Implements
Namespace: Metalama.Patterns.Contracts
Assembly: Metalama.Patterns.Contracts.dll
Syntax
public class RegularExpressionAttribute : RegularExpressionBaseAttribute, IAspect<IParameter>, IEligible<IParameter>, IAspect<IFieldOrPropertyOrIndexer>, IEligible<IFieldOrPropertyOrIndexer>, IConditionallyInheritableAspect, IAspect, ICompileTimeSerializable, ITemplateProviderRemarks
To create a reusable regular expression contract, derive from RegularExpressionBaseAttribute and override GetRegex().
Constructors
| Name | Description |
|---|---|
| RegularExpressionAttribute(string, RegexOptions) | Initializes a new instance of the RegularExpressionAttribute class. |
Properties
| Name | Description |
|---|---|
| Options | Gets the options that modify the regular expression. |
| Pattern | Gets the regular expression pattern to match against. |
Methods
| Name | Description |
|---|---|
| GetRegex() | When implemented in a derived class, returns an expression that evaluates to the Regex used for validation. |