/// <summary> /// Creates an error validation result for this validator. /// </summary> /// <param name="context">The validator context</param> /// <returns>Returns an error validation result.</returns> protected virtual ValidationFailure CreateValidationError(PropertyValidatorContext context) { Func <PropertyValidatorContext, string> errorBuilder = context.Rule.MessageBuilder ?? BuildErrorMessage; var error = errorBuilder(context); var failure = new ValidationFailure(context.PropertyName, error, context.PropertyValue); failure.FormattedMessageArguments = context.MessageFormatter.AdditionalArguments; failure.FormattedMessagePlaceholderValues = context.MessageFormatter.PlaceholderValues; failure.ResourceName = errorSource.ResourceName; failure.ErrorCode = (errorCodeSource != null) ? errorCodeSource.GetString(context.Instance) : LanguageManager.BackwardsCompatibilityCodeMapping(originalErrorSource.ResourceName); if (CustomStateProvider != null) { failure.CustomState = CustomStateProvider(context.Instance); } failure.Severity = Severity; return(failure); }