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)
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class TrimAttribute : MutationAttributeThe 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.
| Name | Description |
|---|---|
| TrimAttribute(Char[]) | Initializes a new instance of the TrimAttribute class. |
| 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. |
| Name | Description |
|---|---|
| Mutate(Object, IMutationContext) | Mutates the given value according to this MutationAttribute. |
| MutateValue(Object, IMutationContext) | Implements the mutation logic for this TrimAttribute. |
Initializes a new instance of the TrimAttribute class.
public TrimAttribute(
params char[] characters
)- characters
- Type: System.Char[]
An array of Unicode characters to remove, or **null**.
Gets an array of Unicode characters to remove.
public char[] Characters { get; private set; }- Type
- System.Char[]
Gets or sets a value indicating the trimming direction.
public TrimOptions Direction { get; set; }- Type
- Dado.ComponentModel.DataMutations.TrimOptions
Gets or sets a value indicating the priority that determines the order in which MutationAttributes are evaluated. Defaults to 40.
public override int Priority { get; set; } = 40;- Type
- System.Int32
Implements the mutation logic for this TrimAttribute.
protected override object MutateValue(
object value,
IMutationContext context
)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.
- value
- Type: System.Object
The value to mutate. - context
- Type: Dado.ComponentModel.DataMutations.IMutationContext
Describes thevaluebeing mutated and provides services and context for mutation.