/// <summary> /// Gets the index of the first occurrence of the specified shaped string within the shaped string segment. /// </summary> /// <param name="value">The shaped string for which to search.</param> /// <returns>The index of the first occurrence of the specified shaped string, or -1 if the segment does not contain the shaped string.</returns> public Int32 IndexOf(IStringSource <ShapedChar> value) { Contract.Require(value, nameof(value)); if (Source is IStringSource <ShapedChar> src) { for (int i = 0; i < Length; i++) { var matches = 0; for (int j = 0; j < value.Length; j++) { if (src[i + j] != value[j]) { break; } matches++; } if (matches == value.Length) { return(i); } } } return(-1); }
protected PropertyValidator(string errorMessageResourceName, Type errorMessageResourceType) { errorMessageResourceName.Guard("errorMessageResourceName must be specified."); errorMessageResourceType.Guard("errorMessageResourceType must be specified."); errorSource = new LocalizedStringSource(errorMessageResourceType, errorMessageResourceName); }
protected PropertyValidator(IStringSource errorMessageSource) { if (errorMessageSource == null) { errorMessageSource = new StaticStringSource("No default error message has been specified."); } errorSource = errorMessageSource; }
public void SetUp() { _propertyValidator = new NotNullValidator(); _validatorGlobalizationServiceMock = MockRepository.GenerateStrictMock <IErrorMessageGlobalizationService>(); _orginalStringSourceMock = MockRepository.GenerateStrictMock <IStringSource> (); _stringSource = new ErrorMessageStringSource(_propertyValidator, _validatorGlobalizationServiceMock, _orginalStringSourceMock); }
protected PropertyValidator(IStringSource stringSource, ValidationMessageType validationMessageType, params LambdaExpression[] relatedProperties) { _stringSource = stringSource; _validationMessageType = validationMessageType; _relatedProperties = new HashSet <string>(); AddRelatedProperties(relatedProperties); }
protected AbstractComparisonValidator( IStringSource stringSource, Expression <Func <TObject, TParam> > valueToCompareExpression, IComparer comparer, ValidationMessageType validationMessageType) : base(stringSource, validationMessageType, valueToCompareExpression) { _comparer = comparer ?? Comparer <TProp> .Default; _valueToCompare = valueToCompareExpression.GetParameterInfo(); }
internal LengthValidator(int min, int max, IStringSource errorSource) : base(errorSource) { Max = max; Min = min; if (max != -1 && max < min) { throw new ArgumentOutOfRangeException(nameof(max), "Max should be larger than min."); } }
public ValidationContext(TObject validatableObject, string propertyName, IStringSource displayPropertySource, TProp propertyValue) { ValidatableObject = validatableObject; PropertyName = propertyName; DisplayPropertySource = displayPropertySource; PropertyValue = propertyValue; _messageArguments = new Dictionary <string, IStringSource> { { nameof(PropertyName), DisplayPropertySource ?? new StaticStringSource(propertyName) } }; }
protected PropertyValidator(IStringSource errorMessageSource) { if (errorMessageSource == null) { errorMessageSource = new StaticStringSource("No default error message has been specified."); } else if (errorMessageSource is LanguageStringSource l) { errorMessageSource = new ErrorCodeLanguageStringSource(ctx => Options.ErrorCodeSource?.GetString(ctx), l); } Options.ErrorMessageSource = errorMessageSource; }
public ValidationMessage(IStringSource stringSource, ValidationMessageType validationMessageType = ValidationMessageType.Error) { _stringSource = stringSource; ValidationMessageType = validationMessageType; Message = _stringSource.GetString(); if (ValidationOptions.LanguageManager.TrackCultureChanged == true) { WeakEventManager <ILanguageManager, CultureChangedEventArgs> .AddHandler( ValidationOptions.LanguageManager, nameof(ILanguageManager.CultureChanged), OnCultureChanged); } }
protected PropertyValidator(IStringSource errorMessageSource) { if (errorMessageSource == null) { errorMessageSource = new StaticStringSource("No default error message has been specified."); } else if (errorMessageSource is LanguageStringSource l && l.ErrorCodeFunc == null) { l.ErrorCodeFunc = ctx => ErrorCodeSource?.GetString(ctx); } ErrorMessageSource = errorMessageSource; }
public ErrorMessageStringSource( IPropertyValidator propertyValidator, IErrorMessageGlobalizationService errorMessageGlobalizationService, IStringSource fallbackErrorMessageSource) { ArgumentUtility.CheckNotNull("propertyValidator", propertyValidator); ArgumentUtility.CheckNotNull("errorMessageGlobalizationService", errorMessageGlobalizationService); ArgumentUtility.CheckNotNull("fallbackErrorMessageSource", fallbackErrorMessageSource); _propertyValidator = propertyValidator; _errorMessageGlobalizationService = errorMessageGlobalizationService; _fallbackErrorMessageSource = fallbackErrorMessageSource; _resourceName = propertyValidator.GetType().FullName; _resourceType = errorMessageGlobalizationService.GetType(); }
protected LengthValidator( IStringSource stringSource, Expression <Func <TObject, int> > minLengthExpression, Expression <Func <TObject, int> > maxLengthExpression, ValidationMessageType validationMessageType) : base(stringSource, validationMessageType, minLengthExpression, maxLengthExpression) { if (minLengthExpression != null) { _minLength = minLengthExpression.GetParameterInfo(); } if (maxLengthExpression != null) { _maxLength = maxLengthExpression.GetParameterInfo(); } }
public void SetUp() { _defaultMessageEvaluatorMock = MockRepository.GenerateStrictMock <IDefaultMessageEvaluator>(); _validatorGlobalizationServiceMock = MockRepository.GenerateStrictMock <IErrorMessageGlobalizationService>(); _validator1 = new NotNullValidator(); _errorMessageSource1 = _validator1.ErrorMessageSource; _validator2 = new NotEmptyValidator(null); _errorMessageSource2 = _validator2.ErrorMessageSource; _validator3 = new NotEqualValidator("test"); _errorMessageSource3 = _validator3.ErrorMessageSource; _propertyRule = PropertyRule.Create(ExpressionHelper.GetTypedMemberExpression <Customer, string> (c => c.LastName)); _propertyRule.AddValidator(_validator1); _propertyRule.AddValidator(_validator2); _propertyRule.AddValidator(_validator3); _service = new ValidationRuleGlobalizationService(_defaultMessageEvaluatorMock, _validatorGlobalizationServiceMock); }
public MessageBuilderContext(PropertyValidatorContext innerContext, IStringSource errorSource, IPropertyValidator propertyValidator) { _innerContext = innerContext; ErrorSource = errorSource; PropertyValidator = propertyValidator; }
protected PropertyValidator(string errorMessageResourceName, Type errorMessageResourceType, string errorCode) { this.errorSource = new LocalizedStringSource(errorMessageResourceType, errorMessageResourceName, new FallbackAwareResourceAccessorBuilder()); this.errorCode = errorCode; }
internal LengthValidator(Func <object, int> min, Func <object, int> max, IStringSource errorSource) : base(errorSource) { MaxFunc = max; MinFunc = min; }
public TestValidator(IStringSource errorMessageSource) : base(errorMessageSource) { }
/// <summary> /// </summary> /// <param name="valueToCompareFunc"></param> /// <param name="member"></param> /// <param name="resourceName"></param> /// <param name="resourceType"></param> protected AbstractComparisonValidator(Func <object, object> valueToCompareFunc, MemberInfo member, IStringSource errorSource) : base(errorSource) { this.valueToCompareFunc = valueToCompareFunc; this.MemberToCompare = member; }
protected PropertyValidator(string errorMessageResourceName, Type errorMessageResourceType) { originalErrorSource = errorSource = new LocalizedStringSource(errorMessageResourceType, errorMessageResourceName, new FallbackAwareResourceAccessorBuilder()); }
/// <summary>Initializes a new instance of the NServiceKit.FluentValidation.Validators.PropertyValidator class.</summary> /// /// <param name="errorMessage">Message describing the error.</param> /// <param name="errorCode"> The error code.</param> protected PropertyValidator(string errorMessage, string errorCode) { this.errorSource = new StaticStringSource(errorMessage); this.errorCode = errorCode; }
protected PropertyValidator(string errorMessage) { errorSource = new StaticStringSource(errorMessage); }
protected static string GetValidationMessage(IStringSource source) { return(source.ResourceType == null?source.GetString(null) : null); }
/// <summary>Initializes a new instance of the NServiceKit.FluentValidation.Validators.PropertyValidator class.</summary> /// /// <param name="errorMessageResourceName">Name of the error message resource.</param> /// <param name="errorMessageResourceType">Type of the error message resource.</param> /// <param name="errorCode"> The error code.</param> protected PropertyValidator(string errorMessageResourceName, Type errorMessageResourceType, string errorCode) { this.errorSource = new LocalizedStringSource(errorMessageResourceType, errorMessageResourceName, new FallbackAwareResourceAccessorBuilder()); this.errorCode = errorCode; }
protected PropertyValidator(IStringSource errorMessageSource) { originalErrorSource = errorSource = errorMessageSource; }
protected PropertyValidator(string errorMessageResourceName, Type errorMessageResourceType) { originalErrorSource = errorSource = new LocalizedStringSource(errorMessageResourceType, errorMessageResourceName); }
protected AsyncValidatorBase(IStringSource errorSource) : base(errorSource) { }
protected PropertyValidator(string errorMessage, string errorCode) { this.errorSource = new StaticStringSource(errorMessage); this.errorCode = errorCode; }
protected PropertyValidator(Expression<Func<string>> errorMessageResourceSelector, string errorCode) { this.errorSource = LocalizedStringSource.CreateFromExpression(errorMessageResourceSelector, new FallbackAwareResourceAccessorBuilder()); this.errorCode = errorCode; }
public BackwardsCompatFormatArgStringSource(IStringSource inner, List <Func <object, object, object> > funcs) { _inner = inner; _customFormatArgs = funcs; }
/// <summary>Initializes a new instance of the NServiceKit.FluentValidation.Validators.PropertyValidator class.</summary> /// /// <param name="errorMessageResourceSelector">The error message resource selector.</param> /// <param name="errorCode"> The error code.</param> protected PropertyValidator(Expression <Func <string> > errorMessageResourceSelector, string errorCode) { this.errorSource = LocalizedStringSource.CreateFromExpression(errorMessageResourceSelector, new FallbackAwareResourceAccessorBuilder()); this.errorCode = errorCode; }
/// <summary> /// </summary> /// <param name="value"></param> /// <param name="resourceName"></param> /// <param name="resourceType"></param> protected AbstractComparisonValidator(IComparable value, IStringSource errorSource) : base(errorSource) { value.Guard("value must not be null."); ValueToCompare = value; }
protected PropertyValidator(Expression <Func <string> > errorMessageResourceSelector) { errorSource = OverridableLocalizedStringSource.CreateFromExpression(errorMessageResourceSelector); }