Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Latest commit

 

History

History
184 lines (121 loc) · 5.01 KB

RegexReplaceAttribute.md

File metadata and controls

184 lines (121 loc) · 5.01 KB

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)

Syntax

[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class RegexReplaceAttribute : MutationAttribute

Remarks

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.

Constructors

Name Description
RegexReplaceAttribute(String) Initializes a new instance of the RegexReplaceAttribute class.
RegexReplaceAttribute(String[]) Initializes a new instance of the RegexReplaceAttribute class.

Properties

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.

Methods

Name Description
Mutate(Object, IMutationContext) Mutates the given value according to this MutationAttribute.
MutateValue(Object, IMutationContext) Implements the mutation logic for this RegexReplaceAttribute.

RegexReplaceAttribute(String)

Initializes a new instance of the RegexReplaceAttribute class.

Syntax

public RegexReplaceAttribute(
	string pattern
)

Parameters

pattern
Type: System.String
The regular expression pattern to match.

RegexReplaceAttribute(String[])

Initializes a new instance of the RegexReplaceAttribute class.

Syntax

public RegexReplaceAttribute(
	string[] patterns
)

Parameters

patterns
Type: System.String[]
The regular expression patterns to match.

Options

Gets or sets a bitwise combination of the enumeration values that modify the regular expression.

Syntax

public RegexOptions Options { get; set; }
Type
System.Text.RegularExpressions.RegexOptions

Patterns

Gets the regular expression pattern to match in a string.

Syntax

public IEnumerable<string> Patterns { get; private set; }
Type
System.Collections.Generic.IEnumerable<System.String>

Priority

Gets or sets a value indicating the priority that determines the order in which MutationAttributes are evaluated. Defaults to 20.

Syntax

public override int Priority { get; set; } = 20;
Type
System.Int32

Replacement

Gets or sets the replacement pattern that will be used to replace each match of the specified Patterns.

Syntax

public string Replacement { get; set; }
Type
System.String

MutateValue(Object, IMutationContext)

Implements the mutation logic for this RegexReplaceAttribute.

Syntax

protected override object MutateValue(
	object value,
	IMutationContext context
)

Returns

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.

Parameters

value
Type: System.Object
The value to mutate.
context
Type: Dado.ComponentModel.DataMutations.IMutationContext
Describes the value being mutated and provides services and context for mutation.