RegexReplaceAttribute ..
Used to mutate a string replacing all strings that match a regular expression pattern with a specified replacement string.
Namespace: Dado.ComponentModel.DataMutations
Implements: Dado.ComponentModel.DataMutations.MutationAttribute (in Dado.ComponentModel.Mutations)
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class RegexReplaceAttribute : MutationAttribute
If Replacement is null, each match of the specified Patterns are removed.
The Replacement property specifies the string that is to replace each match in the current value. Replacement can consist of any combination of literal text and substitutions. For example, the replacement pattern, *${test}b
, inserts the string, "a*", followed by the substring that is matched by the test capturing group, if any, followed by the string, "b". An asterisk (*) is not recognized as a metacharacter within a replacement pattern.
Name | Description |
---|---|
RegexReplaceAttribute(String) | Initializes a new instance of the RegexReplaceAttribute class. |
RegexReplaceAttribute(String[]) | Initializes a new instance of the RegexReplaceAttribute class. |
Name | Description |
---|---|
Options | Gets or sets a bitwise combination of the enumeration values that modify the regular expression. |
Patterns | Gets the regular expression pattern to match in a string. |
Priority | Gets or sets a value indicating the priority that determines the order in which MutationAttributes are evaluated. |
Replacement | Gets or sets the replacement pattern that will be used to replace each match of the specified Patterns. |
RequiresContext | A flag indicating the attribute requires a non-null MutationContext<T> to perform validation. |
Name | Description |
---|---|
Mutate(Object, IMutationContext) | Mutates the given value according to this MutationAttribute. |
MutateValue(Object, IMutationContext) | Implements the mutation logic for this RegexReplaceAttribute. |
Initializes a new instance of the RegexReplaceAttribute class.
public RegexReplaceAttribute(
string pattern
)
- pattern
- Type: System.String
The regular expression pattern to match.
Initializes a new instance of the RegexReplaceAttribute class.
public RegexReplaceAttribute(
string[] patterns
)
- patterns
- Type: System.String[]
The regular expression patterns to match.
Gets or sets a bitwise combination of the enumeration values that modify the regular expression.
public RegexOptions Options { get; set; }
- Type
- System.Text.RegularExpressions.RegexOptions
Gets the regular expression pattern to match in a string.
public IEnumerable<string> Patterns { get; private set; }
- Type
- System.Collections.Generic.IEnumerable<System.String>
Gets or sets a value indicating the priority that determines the order in which MutationAttributes are evaluated. Defaults to 20
.
public override int Priority { get; set; } = 20;
- Type
- System.Int32
Gets or sets the replacement pattern that will be used to replace each match of the specified Patterns.
public string Replacement { get; set; }
- Type
- System.String
Implements the mutation logic for this RegexReplaceAttribute.
protected override object MutateValue(
object value,
IMutationContext context
)
A new string that is identical to the input string, except that the replacement string takes the place of each matched string. If the regular expression pattern is not matched in the current instance, the method returns the current instance unchanged.
- value
- Type: System.Object
The value to mutate. - context
- Type: Dado.ComponentModel.DataMutations.IMutationContext
Describes thevalue
being mutated and provides services and context for mutation.