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

Latest commit

 

History

History
145 lines (95 loc) · 4.15 KB

File metadata and controls

145 lines (95 loc) · 4.15 KB

TrimAttribute ..

Used to mutate a specified string in which all leading and/or trailing occurrences of a set of specified characters are removed.

Namespace: Dado.ComponentModel.DataMutations
Implements: Dado.ComponentModel.DataMutations.MutationAttribute (in Dado.ComponentModel.Mutations)

Syntax

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

Remarks

The Trim attribute removes from the specified string all leading and/or trailing characters that are specified in Characters. Each leading and trailing trim operation stops when a character that is not in Characters is encountered. For example, if the string is "123abc456xyz789" and Characters contains the digits from "1" through "9", the resulting string is "abc456xyz".

If the specified string equals Empty or all the characters in the string consist of characters in the Characters array, the resulting string is Empty.

If Characters is null or an empty array, mutation removes any leading or trailing characters that result in Char.IsWhiteSpace(char) returning true when the character is passed to the method.

Constructors

Name Description
TrimAttribute(Char[]) Initializes a new instance of the TrimAttribute class.

Properties

Name Description
Characters Gets an array of Unicode characters to remove.
Direction Gets or sets a value indicating the trimming direction.
Priority Gets or sets a value indicating the priority that determines the order in which MutationAttributes are evaluated.
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 TrimAttribute.

TrimAttribute(Char[])

Initializes a new instance of the TrimAttribute class.

Syntax

public TrimAttribute(
	params char[] characters
)

Parameters

characters
Type: System.Char[]
An array of Unicode characters to remove, or **null**.

Characters

Gets an array of Unicode characters to remove.

Syntax

public char[] Characters { get; private set; }
Type
System.Char[]

Direction

Gets or sets a value indicating the trimming direction.

Syntax

public TrimOptions Direction { get; set; }
Type
Dado.ComponentModel.DataMutations.TrimOptions

Priority

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

Syntax

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

MutateValue(Object, IMutationContext)

Implements the mutation logic for this TrimAttribute.

Syntax

protected override object MutateValue(
	object value,
	IMutationContext context
)

Returns

The string that remains after all occurrences of the characters in the the Characters array are removed from the start and/or end of the specified string. If the Characters array is null or an empty array, white-space characters are removed instead.

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.