Skip to main content

PropertyValidator

Assembly: ServiceStack.dll​
View Source​
Declaration
public abstract class PropertyValidator : PropertyValidatorOptions, IPropertyValidator

Properties​

Options​

Additional options for configuring the property validator.

View Source​
Declaration
public PropertyValidatorOptions Options { get; }

Inherited Properties​

AsyncCondition​

Async condition associated with the validator. If the condition fails, the validator will not run.

View Source​
Declaration
[Obsolete("The AsyncCondition property will not be accessible in FluentValidation 10. Use the HasAsyncCondition property to check if a condition is set.")]
public Func<PropertyValidatorContext, CancellationToken, Task<bool>> AsyncCondition { get; }

Condition​

Condition associated with the validator. If the condition fails, the validator will not run.

View Source​
Declaration
[Obsolete("The Condition property will not be accessible in FluentValidation 10. Use the HasCondition property to check if a condition is set.")]
public Func<PropertyValidatorContext, bool> Condition { get; }

CustomStateProvider​

Function used to retrieve custom state for the validator

View Source​
Declaration
public Func<PropertyValidatorContext, object> CustomStateProvider { get; set; }

ErrorCode​

Retrieves the error code.

View Source​
Declaration
public string ErrorCode { get; set; }

ErrorCodeSource​

Retrieves the error code.

View Source​
Declaration
[Obsolete("ErrorCodeSource is deprecated and will be removed FluentValidation 10. Please use the ErrorCode property instead.")]
public IStringSource ErrorCodeSource { get; set; }

ErrorMessageSource​

Retrieves the unformatted error message template.

View Source​
Declaration
[Obsolete("ErrorMessageSource is deprecated and will be removed in FluentValidation 10. Please use SetErrorMessage and GetErrorMessageTemplate instead.")]
public IStringSource ErrorMessageSource { get; set; }

HasAsyncCondition​

Whether or not this validator has an async condition associated with it.

View Source​
Declaration
public bool HasAsyncCondition { get; }

HasCondition​

Whether or not this validator has a condition associated with it.

View Source​
Declaration
public bool HasCondition { get; }

SeverityProvider​

Function used to retrieve the severity for the validator

View Source​
Declaration
public Func<PropertyValidatorContext, Severity> SeverityProvider { get; set; }

Methods​

Localized(String)​

Retrieves a localized string from the LanguageManager. If an ErrorCode is defined for this validator, the error code is used as the key. If no ErrorCode is defined (or the language manager doesn't have a translation for the error code) then the fallback key is used instead.

View Source​
Declaration
protected string Localized(string fallbackKey)
Returns​

System.String: The translated error message template.

Parameters​
TypeNameDescription
System.StringfallbackKeyThe fallback key to use for translation, if no ErrorCode is available.

|

Validate(PropertyValidatorContext)​

Performs validation

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

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

Parameters​
TypeName
ServiceStack.FluentValidation.Validators.PropertyValidatorContextcontext

ValidateAsync(PropertyValidatorContext, CancellationToken)​

Performs validation asynchronously.

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

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

Parameters​
TypeName
ServiceStack.FluentValidation.Validators.PropertyValidatorContextcontext
System.Threading.CancellationTokencancellation

ShouldValidateAsynchronously(IValidationContext)​

Determines whether this validator should be run asynchronously or not.

View Source​
Declaration
public virtual bool ShouldValidateAsynchronously(IValidationContext context)
Returns​

System.Boolean

Parameters​
TypeName
ServiceStack.FluentValidation.IValidationContextcontext

IsValid(PropertyValidatorContext)​

View Source​
Declaration
protected abstract bool IsValid(PropertyValidatorContext context)
Returns​

System.Boolean

Parameters​
TypeName
ServiceStack.FluentValidation.Validators.PropertyValidatorContextcontext

IsValidAsync(PropertyValidatorContext, CancellationToken)​

View Source​
Declaration
protected virtual async Task<bool> IsValidAsync(PropertyValidatorContext context, CancellationToken cancellation)
Returns​

System.Threading.Tasks.Task<System.Boolean>

Parameters​
TypeName
ServiceStack.FluentValidation.Validators.PropertyValidatorContextcontext
System.Threading.CancellationTokencancellation

PrepareMessageFormatterForValidationError(PropertyValidatorContext)​

Prepares the ServiceStack.FluentValidation.Internal.MessageFormatter of <code data-dev-comment-type="paramref" class="paramref">context</code> for an upcoming ServiceStack.FluentValidation.Results.ValidationFailure.

View Source​
Declaration
protected virtual void PrepareMessageFormatterForValidationError(PropertyValidatorContext context)
Parameters​
TypeNameDescription
ServiceStack.FluentValidation.Validators.PropertyValidatorContextcontextThe validator context

|

CreateValidationError(PropertyValidatorContext)​

Creates an error validation result for this validator.

View Source​
Declaration
protected virtual ValidationFailure CreateValidationError(PropertyValidatorContext context)
Returns​

ServiceStack.FluentValidation.Results.ValidationFailure: Returns an error validation result.

Parameters​
TypeNameDescription
ServiceStack.FluentValidation.Validators.PropertyValidatorContextcontextThe validator context

|

Inherited Methods​

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

Adds a condition for this validator. If there's already a condition, they're combined together with an AND.

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

ApplyCondition(Func<PropertyValidatorContext, Boolean>)​

Adds a condition for this validator. If there's already a condition, they're combined together with an AND.

View Source​
Declaration
public void ApplyCondition(Func<PropertyValidatorContext, bool> condition)
Parameters​
TypeName
System.Func<ServiceStack.FluentValidation.Validators.PropertyValidatorContext,System.Boolean>condition

GetDefaultMessageTemplate()​

Returns the default error message template for this validator, when not overridden.

View Source​
Declaration
protected virtual string GetDefaultMessageTemplate()
Returns​

System.String

GetErrorMessageTemplate(PropertyValidatorContext)​

Gets the error message. If a context is supplied, it will be used to format the message if it has placeholders. If no context is supplied, the raw unformatted message will be returned, containing placeholders.

View Source​
Declaration
public string GetErrorMessageTemplate(PropertyValidatorContext context)
Returns​

System.String: Either the formatted or unformatted error message.

Parameters​
TypeNameDescription
ServiceStack.FluentValidation.Validators.PropertyValidatorContextcontextThe current property validator context.

|

SetErrorMessage(Func<PropertyValidatorContext, String>)​

Sets the overridden error message template for this validator.

View Source​
Declaration
public void SetErrorMessage(Func<PropertyValidatorContext, string> errorFactory)
Parameters​
TypeNameDescription
System.Func<ServiceStack.FluentValidation.Validators.PropertyValidatorContext,System.String>errorFactoryA function for retrieving the error message template.

|

SetErrorMessage(String)​

Sets the overridden error message template for this validator.

View Source​
Declaration
public void SetErrorMessage(string errorMessage)
Parameters​
TypeNameDescription
System.StringerrorMessageThe error message to set

|

Implements​