PropertyValidator
Assembly: ServiceStack.dll
View Source
public abstract class PropertyValidator : PropertyValidatorOptions, IPropertyValidator
Properties
Options
Additional options for configuring the property validator.
View Source
public PropertyValidatorOptions Options { get; }
Inherited Properties
AsyncCondition
Async condition associated with the validator. If the condition fails, the validator will not run.
View Source
[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
[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
public Func<PropertyValidatorContext, object> CustomStateProvider { get; set; }
ErrorCode
Retrieves the error code.
View Source
public string ErrorCode { get; set; }
ErrorCodeSource
Retrieves the error code.
View Source
[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
[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
public bool HasAsyncCondition { get; }
HasCondition
Whether or not this validator has a condition associated with it.
View Source
public bool HasCondition { get; }
SeverityProvider
Function used to retrieve the severity for the validator
View Source
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
protected string Localized(string fallbackKey)
Returns
System.String
: The translated error message template.
Parameters
Type | Name | Description |
---|---|---|
System.String | fallbackKey | The fallback key to use for translation, if no ErrorCode is available. |
|
Validate(PropertyValidatorContext)
Performs validation
View Source
public virtual IEnumerable<ValidationFailure> Validate(PropertyValidatorContext context)
Returns
System.Collections.Generic.IEnumerable<ServiceStack.FluentValidation.Results.ValidationFailure>
Parameters
Type | Name |
---|---|
ServiceStack.FluentValidation.Validators.PropertyValidatorContext | context |
ValidateAsync(PropertyValidatorContext, CancellationToken)
Performs validation asynchronously.
View Source
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
Type | Name |
---|---|
ServiceStack.FluentValidation.Validators.PropertyValidatorContext | context |
System.Threading.CancellationToken | cancellation |
ShouldValidateAsynchronously(IValidationContext)
Determines whether this validator should be run asynchronously or not.
View Source
public virtual bool ShouldValidateAsynchronously(IValidationContext context)
Returns
System.Boolean
Parameters
Type | Name |
---|---|
ServiceStack.FluentValidation.IValidationContext | context |
IsValid(PropertyValidatorContext)
View Source
protected abstract bool IsValid(PropertyValidatorContext context)
Returns
System.Boolean
Parameters
Type | Name |
---|---|
ServiceStack.FluentValidation.Validators.PropertyValidatorContext | context |
IsValidAsync(PropertyValidatorContext, CancellationToken)
View Source
protected virtual async Task<bool> IsValidAsync(PropertyValidatorContext context, CancellationToken cancellation)
Returns
System.Threading.Tasks.Task<System.Boolean>
Parameters
Type | Name |
---|---|
ServiceStack.FluentValidation.Validators.PropertyValidatorContext | context |
System.Threading.CancellationToken | cancellation |
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
protected virtual void PrepareMessageFormatterForValidationError(PropertyValidatorContext context)
Parameters
Type | Name | Description |
---|---|---|
ServiceStack.FluentValidation.Validators.PropertyValidatorContext | context | The validator context |
|
CreateValidationError(PropertyValidatorContext)
Creates an error validation result for this validator.
View Source
protected virtual ValidationFailure CreateValidationError(PropertyValidatorContext context)
Returns
ServiceStack.FluentValidation.Results.ValidationFailure: Returns an error validation result.
Parameters
Type | Name | Description |
---|---|---|
ServiceStack.FluentValidation.Validators.PropertyValidatorContext | context | The 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
public void ApplyAsyncCondition(Func<PropertyValidatorContext, CancellationToken, Task<bool>> condition)
Parameters
Type | Name |
---|---|
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
public void ApplyCondition(Func<PropertyValidatorContext, bool> condition)
Parameters
Type | Name |
---|---|
System.Func<ServiceStack.FluentValidation.Validators.PropertyValidatorContext,System.Boolean> | condition |
GetDefaultMessageTemplate()
Returns the default error message template for this validator, when not overridden.
View Source
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
public string GetErrorMessageTemplate(PropertyValidatorContext context)
Returns
System.String
: Either the formatted or unformatted error message.
Parameters
Type | Name | Description |
---|---|---|
ServiceStack.FluentValidation.Validators.PropertyValidatorContext | context | The current property validator context. |
|
SetErrorMessage(Func<PropertyValidatorContext, String>)
Sets the overridden error message template for this validator.
View Source
public void SetErrorMessage(Func<PropertyValidatorContext, string> errorFactory)
Parameters
Type | Name | Description |
---|---|---|
System.Func<ServiceStack.FluentValidation.Validators.PropertyValidatorContext,System.String> | errorFactory | A function for retrieving the error message template. |
|
SetErrorMessage(String)
Sets the overridden error message template for this validator.
View Source
public void SetErrorMessage(string errorMessage)
Parameters
Type | Name | Description |
---|---|---|
System.String | errorMessage | The error message to set |
|