Skip to main content
Version: Preview (0.3.0-preview.205)

Interface IValueObjectPatternValidator

Namespace: AdCodicem.ValueObjects
Assembly: AdCodicem.ValueObjects.Abstractions.dll

Declares that a string value object must match a regular expression.

public interface IValueObjectPatternValidator

Remarks​

Implement it with a source-generated regular expression, which the regex generator can only write for code a consumer wrote by hand: [GeneratedRegex("^[A-Z]{3}$", RegexOptions.CultureInvariant, matchTimeoutMilliseconds: 1000)] public static partial Regex Pattern { get; }. It runs compiled under native AOT, where a built at run time is interpreted, and costs nothing until it first runs.

The pattern runs after MinLength and MaxLength, before the known values and , and a value it does not match is rejected as . It is declared once: its text is also the OpenAPI pattern, read off the [GeneratedRegex] attribute when the type compiles. That text carries no , so a rule like case insensitivity belongs in the pattern itself.

It replaces the Pattern option of [ValueObject<T>], which builds its regular expression at run time. Implementing it on a value object that is not a string, or on an [EntityId], which owns its format, is a build error.

Properties​

Pattern​

Gets the regular expression a value must match.

public static abstract Regex Pattern { get; }

Property Value​

Regex