Skip to main content

CollectionPropertyRule<T, TElement>

Rule definition for collection properties

Assembly: ServiceStack.dll
View Source
Declaration
public class CollectionPropertyRule<T, TElement> : PropertyRule, IValidationRule

Properties

Filter

Filter that should include/exclude items in the collection.

View Source
Declaration
public Func<TElement, bool> Filter { get; set; }

IndexBuilder

Constructs the indexer in the property name associated with the error message. By default this is "[" + index + "]"

View Source
Declaration
public Func<object, IEnumerable<TElement>, TElement, int, string> IndexBuilder { get; set; }

Inherited Properties

AsyncCondition

Asynchronous condition for all validators in this rule.

View Source
Declaration
[Obsolete("This property will not be accessible in FluentValidation 10. Use HasCondition/HasAsyncCondition to check if the rule has a condition defined")]
public Func<IValidationContext, CancellationToken, Task<bool>> AsyncCondition { get; }

CascadeMode

Cascade mode for this rule.

View Source
Declaration
public CascadeMode CascadeMode { get; set; }

Condition

Condition for all validators in this rule.

View Source
Declaration
[Obsolete("This property will not be accessible in FluentValidation 10. Use HasCondition/HasAsyncCondition to check if the rule has a condition defined")]
public Func<IValidationContext, bool> Condition { get; }

CurrentValidator

The current validator being configured by this rule.

View Source
Declaration
public IPropertyValidator CurrentValidator { get; }

DependentRules

Dependent rules

View Source
Declaration
public List<IValidationRule> DependentRules { get; }

DisplayName

String source that can be used to retrieve the display name (if null, falls back to the property name)

View Source
Declaration
[Obsolete("This property is deprecated and will be removed in FluentValidation 10. Use the GetDisplayName and SetDisplayName instead.")]
public IStringSource DisplayName { get; set; }

Expression

Expression that was used to create the rule.

View Source
Declaration
public LambdaExpression Expression { get; }

HasAsyncCondition

Checks whether this rule has an async condition defined.

View Source
Declaration
public bool HasAsyncCondition { get; }

HasCondition

Checks whether this rule has a condition defined.

View Source
Declaration
public bool HasCondition { get; }

Member

Property associated with this rule.

View Source
Declaration
public MemberInfo Member { get; }

MessageBuilder

Allows custom creation of an error message

View Source
Declaration
public Func<MessageBuilderContext, string> MessageBuilder { get; set; }

OnFailure

Function that will be invoked if any of the validators associated with this rule fail.

View Source
Declaration
public Action<object, IEnumerable<ValidationFailure>> OnFailure { get; set; }

PropertyFunc

Function that can be invoked to retrieve the value of the property.

View Source
Declaration
public Func<object, object> PropertyFunc { get; }

PropertyName

Returns the property name for the property being validated. Returns null if it is not a property being validated (eg a method call)

View Source
Declaration
public string PropertyName { get; set; }

RuleSets

Rule set that this rule belongs to (if specified)

View Source
Declaration
public string[] RuleSets { get; set; }

Transformer

View Source
Declaration
[Obsolete("This property will be removed in FluentValidation 10")]
public Func<object, object> Transformer { get; set; }

TypeToValidate

Type of the property being validated

View Source
Declaration
public Type TypeToValidate { get; }

Validators

Validators associated with this rule.

View Source
Declaration
public IEnumerable<IPropertyValidator> Validators { get; }

Methods

Create(Expression<Func<T, IEnumerable<TElement>>>, Func<CascadeMode>)

Creates a new property rule from a lambda expression.

View Source
Declaration
public static CollectionPropertyRule<T, TElement> Create(Expression<Func<T, IEnumerable<TElement>>> expression, Func<CascadeMode> cascadeModeThunk)
Returns

[ServiceStack.FluentValidation.Internal.CollectionPropertyRule<T, TElement>](../ServiceStack.FluentValidation.Internal/CollectionPropertyRuleT, TElement)

Parameters
TypeName
System.Linq.Expressions.Expression<System.Func<<T>,System.Collections.Generic.IEnumerable<<TElement>>>>expression
System.Func<ServiceStack.FluentValidation.CascadeMode>cascadeModeThunk

InvokePropertyValidatorAsync(IValidationContext, IPropertyValidator, String, CancellationToken)

Invokes the validator asynchronously

View Source
Declaration
protected override async Task<IEnumerable<ValidationFailure>> InvokePropertyValidatorAsync(IValidationContext context, IPropertyValidator validator, string propertyName, CancellationToken cancellation)
Returns

System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<ServiceStack.FluentValidation.Results.ValidationFailure>>

Parameters
TypeName
ServiceStack.FluentValidation.IValidationContextcontext
ServiceStack.FluentValidation.Validators.IPropertyValidatorvalidator
System.StringpropertyName
System.Threading.CancellationTokencancellation

InvokePropertyValidator(IValidationContext, IPropertyValidator, String)

Invokes the validator

View Source
Declaration
protected override IEnumerable<ValidationFailure> InvokePropertyValidator(IValidationContext context, IPropertyValidator validator, string propertyName)
Returns

System.Collections.Generic.IEnumerable<ServiceStack.FluentValidation.Results.ValidationFailure>

Parameters
TypeName
ServiceStack.FluentValidation.IValidationContextcontext
ServiceStack.FluentValidation.Validators.IPropertyValidatorvalidator
System.StringpropertyName

Inherited Methods

AddValidator(IPropertyValidator)

Adds a validator to the rule.

View Source
Declaration
public void AddValidator(IPropertyValidator validator)
Parameters
TypeName
ServiceStack.FluentValidation.Validators.IPropertyValidatorvalidator

ApplyAsyncCondition(Func<PropertyValidatorContext, CancellationToken, Task<Boolean>>, ApplyConditionTo)

Applies the condition to the rule asynchronously

View Source
Declaration
public void ApplyAsyncCondition(Func<PropertyValidatorContext, CancellationToken, Task<bool>> predicate, ApplyConditionTo applyConditionTo = ApplyConditionTo.AllValidators)
Parameters
TypeName
System.Func<ServiceStack.FluentValidation.Validators.PropertyValidatorContext,System.Threading.CancellationToken,System.Threading.Tasks.Task<System.Boolean>>predicate
ServiceStack.FluentValidation.ApplyConditionToapplyConditionTo

ApplyCondition(Func<PropertyValidatorContext, Boolean>, ApplyConditionTo)

Applies a condition to the rule

View Source
Declaration
public void ApplyCondition(Func<PropertyValidatorContext, bool> predicate, ApplyConditionTo applyConditionTo = ApplyConditionTo.AllValidators)
Parameters
TypeName
System.Func<ServiceStack.FluentValidation.Validators.PropertyValidatorContext,System.Boolean>predicate
ServiceStack.FluentValidation.ApplyConditionToapplyConditionTo

ApplySharedAsyncCondition(Func<IValidationContext, CancellationToken, Task<Boolean>>)

View Source
Declaration
public void ApplySharedAsyncCondition(Func<IValidationContext, CancellationToken, Task<bool>> condition)
Parameters
TypeName
System.Func<ServiceStack.FluentValidation.IValidationContext,System.Threading.CancellationToken,System.Threading.Tasks.Task<System.Boolean>>condition

ApplySharedCondition(Func<IValidationContext, Boolean>)

View Source
Declaration
public void ApplySharedCondition(Func<IValidationContext, bool> condition)
Parameters
TypeName
System.Func<ServiceStack.FluentValidation.IValidationContext,System.Boolean>condition

ClearValidators()

Clear all validators from this rule.

View Source
Declaration
public void ClearValidators()

Create<T, TProperty>(Expression<Func<T, TProperty>>)

Creates a new property rule from a lambda expression.

View Source
Declaration
public static PropertyRule Create<T, TProperty>(Expression<Func<T, TProperty>> expression)
Returns

ServiceStack.FluentValidation.Internal.PropertyRule

Parameters
TypeName
System.Linq.Expressions.Expression<System.Func<<T>,<TProperty>>>expression
Type Parameters
  • T
  • TProperty

Create<T, TProperty>(Expression<Func<T, TProperty>>, Func<CascadeMode>, Boolean)

Creates a new property rule from a lambda expression.

View Source
Declaration
public static PropertyRule Create<T, TProperty>(Expression<Func<T, TProperty>> expression, Func<CascadeMode> cascadeModeThunk, bool bypassCache = false)
Returns

ServiceStack.FluentValidation.Internal.PropertyRule

Parameters
TypeName
System.Linq.Expressions.Expression<System.Func<<T>,<TProperty>>>expression
System.Func<ServiceStack.FluentValidation.CascadeMode>cascadeModeThunk
System.BooleanbypassCache
Type Parameters
  • T
  • TProperty

GetDisplayName()

Display name for the property.

View Source
Declaration
[Obsolete("Calling GetDisplayName without a context parameter is deprecated and will be removed in FluentValidation 10. If you really need this behaviour, you can call the overload that takes a context but pass in null.")]
public string GetDisplayName()
Returns

System.String

GetDisplayName(ICommonContext)

Display name for the property.

View Source
Declaration
public string GetDisplayName(ICommonContext context)
Returns

System.String

Parameters
TypeName
ServiceStack.FluentValidation.ICommonContextcontext

InvokePropertyValidator(IValidationContext, IPropertyValidator, String)

Invokes a property validator using the specified validation context.

View Source
Declaration
protected virtual IEnumerable<ValidationFailure> InvokePropertyValidator(IValidationContext context, IPropertyValidator validator, string propertyName)
Returns

System.Collections.Generic.IEnumerable<ServiceStack.FluentValidation.Results.ValidationFailure>

Parameters
TypeName
ServiceStack.FluentValidation.IValidationContextcontext
ServiceStack.FluentValidation.Validators.IPropertyValidatorvalidator
System.StringpropertyName

InvokePropertyValidatorAsync(IValidationContext, IPropertyValidator, String, CancellationToken)

Invokes the validator asynchronously

View Source
Declaration
protected virtual async Task<IEnumerable<ValidationFailure>> InvokePropertyValidatorAsync(IValidationContext context, IPropertyValidator validator, string propertyName, CancellationToken cancellation)
Returns

System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<ServiceStack.FluentValidation.Results.ValidationFailure>>

Parameters
TypeName
ServiceStack.FluentValidation.IValidationContextcontext
ServiceStack.FluentValidation.Validators.IPropertyValidatorvalidator
System.StringpropertyName
System.Threading.CancellationTokencancellation

RemoveValidator(IPropertyValidator)

Remove a validator in this rule.

View Source
Declaration
public void RemoveValidator(IPropertyValidator original)
Parameters
TypeName
ServiceStack.FluentValidation.Validators.IPropertyValidatororiginal

ReplaceValidator(IPropertyValidator, IPropertyValidator)

Replaces a validator in this rule. Used to wrap validators.

View Source
Declaration
public void ReplaceValidator(IPropertyValidator original, IPropertyValidator newValidator)
Parameters
TypeName
ServiceStack.FluentValidation.Validators.IPropertyValidatororiginal
ServiceStack.FluentValidation.Validators.IPropertyValidatornewValidator

SetDisplayName(Func<IValidationContext, String>)

Sets the display name for the property using a function.

View Source
Declaration
public void SetDisplayName(Func<IValidationContext, string> factory)
Parameters
TypeNameDescription
System.Func<ServiceStack.FluentValidation.IValidationContext,System.String>factoryThe function for building the display name

|

SetDisplayName(String)

Sets the display name for the property.

View Source
Declaration
public void SetDisplayName(string name)
Parameters
TypeNameDescription
System.StringnameThe property's display name

|

Validate(IValidationContext)

Performs validation using a validation context and returns a collection of Validation Failures.

View Source
Declaration
public virtual IEnumerable<ValidationFailure> Validate(IValidationContext context)
Returns

System.Collections.Generic.IEnumerable<ServiceStack.FluentValidation.Results.ValidationFailure>: A collection of validation failures

Parameters
TypeNameDescription
ServiceStack.FluentValidation.IValidationContextcontextValidation Context

|

ValidateAsync(IValidationContext, CancellationToken)

Performs asynchronous validation using a validation context and returns a collection of Validation Failures.

View Source
Declaration
public virtual async Task<IEnumerable<ValidationFailure>> ValidateAsync(IValidationContext context, CancellationToken cancellation)
Returns

System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<ServiceStack.FluentValidation.Results.ValidationFailure>>: A collection of validation failures

Parameters
TypeNameDescription
ServiceStack.FluentValidation.IValidationContextcontextValidation Context

| | System.Threading.CancellationToken | cancellation |

|

Implements