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

Latest commit

 

History

History
150 lines (98 loc) · 4.18 KB

File metadata and controls

150 lines (98 loc) · 4.18 KB

ApplyMaxLengthAttribute ..

Used to mutate a string data to the maximum allowable length according to the associated StringLengthAttribute.MaximumLength or MaxLengthAttribute.Length.

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

Syntax

[AttributeUsage(AttributeTargets.Property)]
public class ApplyMaxLengthAttribute : MutationAttribute

Remarks

Since System.Attributes cannot accept generics or lambdas, there is not a practical way to alter the length of collections maintaining their type information. Therefore, ApplyMaxLengthAttribute.CollectionDescriptor can be used to extend ApplyMaxLengthAttribute through its protected constructor.

Expect ApplyMaxLengthAttribute.CollectionDescriptor to be obsolete once generics or lambdas are implemented for System.Attributes.

Constructors

Name Description
ApplyMaxLengthAttribute() Initializes a new instance of the ApplyMaxLengthAttribute class.
ApplyMaxLengthAttribute(CollectionDescriptor) Initializes a new instance of the ApplyMaxLengthAttribute class.

Properties

Name Description
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 IMutationContext to perform validation.

Methods

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

ApplyMaxLengthAttribute()

Initializes a new instance of the ApplyMaxLengthAttribute class.

Syntax

public ApplyMaxLengthAttribute()

ApplyMaxLengthAttribute(CollectionDescriptor)

Initializes a new instance of the ApplyMaxLengthAttribute class.

Syntax

protected ApplyMaxLengthAttribute(
	CollectionDescriptor descriptor
)

Parameters

descriptor
Type: Dado.ComponentModel.DataMutations.ApplyMaxLengthAttribute.CollectionDescriptor
Describe a collection should be mutated.

RequiresContext

A flag indicating the attribute requires a non-null IMutationContext to perform validation. Returns true.

Syntax

public override bool RequiresContext { get; protected set; } = true;
Type
System.Boolean

Mutate(Object, Int32)

Mutates the given value according to this MutationAttribute.

Syntax

public object Mutate(
	object value,
	int maximumLength
)

Returns

The resulting mutated value.

Parameters

value
Type: System.Object
The value to mutate.
maximumLength
Type: System.Int32
The maximum allowable length to apply to the string data.

MutateValue(Object, IMutationContext)

Implements the mutation logic for this ApplyMaxLengthAttribute.

Syntax

protected override object MutateValue(
	object value,
	IMutationContext context
)

Returns

The truncated string data when the specified value exceeds the maximum allowable length.

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.