Base class for contract aspects that validate strings against regular expressions.
Inheritance
Implements
Namespace: Metalama.Patterns.Contracts
Assembly: Metalama.Patterns.Contracts.dll
Syntax
public abstract class RegularExpressionBaseAttribute : ContractBaseAttribute, IAspect<IParameter>, IEligible<IParameter>, IAspect<IFieldOrPropertyOrIndexer>, IEligible<IFieldOrPropertyOrIndexer>, IConditionallyInheritableAspect, IAspect, ICompileTimeSerializable, ITemplateProviderRemarks
Derived classes must implement GetRegex() to provide the regular expression used for validation. If the target is a nullable type, null strings are accepted and do not throw an exception.
To customize the behavior when validation fails, override the OnContractViolated(dynamic?, dynamic, ContractContext) template method.
Constructors
| Name | Description |
|---|---|
| RegularExpressionBaseAttribute() |
Methods
| Name | Description |
|---|---|
| BuildEligibility(IEligibilityBuilder<IFieldOrPropertyOrIndexer>) | Configures the eligibility of the aspect or attribute by defining rules that determine which declarations the aspect can be applied to. |
| BuildEligibility(IEligibilityBuilder<IParameter>) | Configures the eligibility of the aspect or attribute by defining rules that determine which declarations the aspect can be applied to. |
| GetRegex() | When implemented in a derived class, returns an expression that evaluates to the Regex used for validation. |
| OnContractViolated(dynamic?, dynamic, ContractContext) | Template method called when the contract validation fails. Override to customize the error behavior. |
| Validate(dynamic?) | The template method that validates or normalizes the value of a field, property, indexer, or parameter. |