Skip to main content

ScalePrecisionValidator

Allows a decimal to be validated for scale and precision. Scale would be the number of digits to the right of the decimal point. Precision would be the number of digits. This number includes both the left and the right sides of the decimal point.

It can be configured to use the effective scale and precision (i.e. ignore trailing zeros) if required.

123.4500 has an scale of 4 and a precision of 7, but an effective scale and precision of 2 and 5 respectively.

Assembly: ServiceStack.dll
View Source
Declaration
public class ScalePrecisionValidator : PropertyValidator, IPropertyValidator

Properties

Scale

View Source
Declaration
public int Scale { get; set; }

Precision

View Source
Declaration
public int Precision { get; set; }

IgnoreTrailingZeros

View Source
Declaration
public bool IgnoreTrailingZeros { get; set; }

Inherited Properties

Options

Additional options for configuring the property validator.

View Source
Declaration
public PropertyValidatorOptions Options { get; }

Methods

IsValid(PropertyValidatorContext)

View Source
Declaration
protected override bool IsValid(PropertyValidatorContext context)
Returns

System.Boolean

Parameters
TypeName
ServiceStack.FluentValidation.Validators.PropertyValidatorContextcontext

GetDefaultMessageTemplate()

View Source
Declaration
protected override string GetDefaultMessageTemplate()
Returns

System.String

Inherited Methods

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

|

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

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.

|

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

|

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

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

Implements