/// <summary> /// Creates the <see cref="PropertyComparisonValidator"/> described by the configuration object. /// </summary> /// <param name="targetType">The type of object that will be validated by the validator.</param> /// <param name="ownerType">The type of the object from which the value to validate is extracted.</param> /// <param name="memberValueAccessBuilder">The <see cref="MemberValueAccessBuilder"/> to use for validators that /// require access to properties.</param> /// <param name="validatorFactory">Factory to use when building nested validators.</param> /// <returns>The created <see cref="PropertyComparisonValidator"/>.</returns> protected override Validator DoCreateValidator( Type targetType, Type ownerType, MemberValueAccessBuilder memberValueAccessBuilder, ValidatorFactory validatorFactory) { if (string.IsNullOrEmpty(this.PropertyToCompare)) { throw new ConfigurationErrorsException(Resources.ExceptionPropertyToCompareNull); } PropertyInfo propertyInfo = ValidationReflectionHelper.GetProperty(ownerType, this.PropertyToCompare, false); if (propertyInfo == null) { throw new ConfigurationErrorsException( string.Format( CultureInfo.CurrentCulture, Resources.ExceptionPropertyToCompareNotFound, this.PropertyToCompare, ownerType.FullName)); } return new PropertyComparisonValidator(memberValueAccessBuilder.GetPropertyValueAccess(propertyInfo), this.ComparisonOperator, this.Negated); }
/// <summary> /// Creates the <see cref="PropertyComparisonValidator"/> described by the configuration object. /// </summary> /// <param name="targetType">The type of object that will be validated by the validator.</param> /// <param name="ownerType">The type of the object from which the value to validate is extracted.</param> /// <param name="memberValueAccessBuilder">The <see cref="MemberValueAccessBuilder"/> to use for validators that /// require access to properties.</param> /// <param name="validatorFactory">Factory to use when building nested validators.</param> /// <returns>The created <see cref="PropertyComparisonValidator"/>.</returns> protected override Validator DoCreateValidator( Type targetType, Type ownerType, MemberValueAccessBuilder memberValueAccessBuilder, ValidatorFactory validatorFactory) { if (string.IsNullOrEmpty(this.PropertyToCompare)) { throw new ConfigurationErrorsException(Resources.ExceptionPropertyToCompareNull); } PropertyInfo propertyInfo = ValidationReflectionHelper.GetProperty(ownerType, this.PropertyToCompare, false); if (propertyInfo == null) { throw new ConfigurationErrorsException( string.Format( CultureInfo.CurrentCulture, Resources.ExceptionPropertyToCompareNotFound, this.PropertyToCompare, ownerType.FullName)); } return(new PropertyComparisonValidator(memberValueAccessBuilder.GetPropertyValueAccess(propertyInfo), this.ComparisonOperator, this.Negated)); }
/// <summary> /// Creates the <see cref="Validator"/> described by the configuration object. /// </summary> /// <param name="targetType">The type of object that will be validated by the validator.</param> /// <param name="ownerType"></param> /// <param name="memberValueAccessBuilder"></param> /// <returns>The created <see cref="Validator"/>.</returns> /// <remarks> /// Sets the tag and message template to the created validator. /// </remarks> Validator IValidatorDescriptor.CreateValidator(Type targetType, Type ownerType, MemberValueAccessBuilder memberValueAccessBuilder) { Validator validator = DoCreateValidator(targetType, ownerType, memberValueAccessBuilder); validator.Tag = this.Tag; validator.MessageTemplate = this.GetMessageTemplate(); return validator; }
Validator IValidatorDescriptor.CreateValidator( Type targetType, Type ownerType, MemberValueAccessBuilder memberValueAccessBuilder, ValidatorFactory validatorFactory) { return CreateValidator(targetType, ownerType, memberValueAccessBuilder, validatorFactory); }
Validator IValidatorDescriptor.CreateValidator( Type targetType, Type ownerType, MemberValueAccessBuilder memberValueAccessBuilder, ValidatorFactory validatorFactory) { return(CreateValidator(targetType, ownerType, memberValueAccessBuilder, validatorFactory)); }
/// <summary> /// Creates the <see cref="Validator"/> described by the configuration object. /// </summary> /// <param name="targetType">The type of object that will be validated by the validator.</param> /// <param name="ownerType">The type of the object from which the value to validate is extracted.</param> /// <param name="memberValueAccessBuilder">The <see cref="MemberValueAccessBuilder"/> to use for validators that /// require access to properties.</param> /// <param name="validatorFactory">Factory to use when building nested validators.</param> /// <returns>The created <see cref="Validator"/>.</returns> /// <remarks> /// The default implementation invokes <see cref="ValidatorAttribute.DoCreateValidator(Type)"/>. Subclasses requiring access to all /// the parameters or this method may override it instead of <see cref="ValidatorAttribute.DoCreateValidator(Type)"/>. /// </remarks> protected virtual Validator DoCreateValidator( Type targetType, Type ownerType, MemberValueAccessBuilder memberValueAccessBuilder, ValidatorFactory validatorFactory) { return(DoCreateValidator(targetType)); }
/// <summary> /// Creates the <see cref="OrCompositeValidator"/> described by the configuration object. /// </summary> /// <param name="targetType">The type of object that will be validated by the validator.</param> /// <param name="ownerType">The type of the object from which the value to validate is extracted.</param> /// <param name="memberValueAccessBuilder">The <see cref="MemberValueAccessBuilder"/> to use for validators that /// require access to properties.</param> /// <returns>The created <see cref="OrCompositeValidator"/>.</returns> protected override Validator DoCreateValidator(Type targetType, Type ownerType, MemberValueAccessBuilder memberValueAccessBuilder) { List<Validator> childValidators = new List<Validator>(this.Validators.Count); foreach (IValidatorDescriptor validatorData in this.Validators) { childValidators.Add(validatorData.CreateValidator(targetType, ownerType, memberValueAccessBuilder)); } return new OrCompositeValidator(childValidators.ToArray()); }
protected Validator CreateValidator(Type targetType, Type ownerType, MemberValueAccessBuilder memberValueAccessBuilder, ValidatorFactory validatorFactory) { Validator validator = DoCreateValidator(targetType, ownerType, memberValueAccessBuilder, validatorFactory); validator.Tag = Tag; validator.MessageTemplate = GetMessageTemplate(); return(validator); }
/// <summary> /// Creates the <see cref="Validator"/> described by the configuration object. /// </summary> /// <param name="targetType">The type of object that will be validated by the validator.</param> /// <param name="ownerType">The type of the object from which the value to validate is extracted.</param> /// <param name="memberValueAccessBuilder">The <see cref="MemberValueAccessBuilder"/> to use for validators that /// require access to properties.</param> /// <param name="validatorFactory">Factory to use when building nested validators.</param> /// <returns>The created <see cref="Validator"/>.</returns> /// <remarks> /// Sets the tag and message template to the created validator. /// </remarks> protected Validator CreateValidator( Type targetType, Type ownerType, MemberValueAccessBuilder memberValueAccessBuilder, ValidatorFactory validatorFactory) { Validator validator = DoCreateValidator(targetType, ownerType, memberValueAccessBuilder, validatorFactory); validator.Tag = this.Tag; validator.MessageTemplate = this.GetMessageTemplate(); return validator; }
/// <summary> /// Creates the <see cref="Validator"/> described by the configuration object. /// </summary> /// <param name="targetType">The type of object that will be validated by the validator.</param> /// <param name="ownerType">The type of the object from which the value to validate is extracted.</param> /// <param name="memberValueAccessBuilder">The <see cref="MemberValueAccessBuilder"/> to use for validators that /// require access to properties.</param> /// <param name="validatorFactory">Factory to use when building nested validators.</param> /// <returns>The created <see cref="Validator"/>.</returns> Validator IValidatorDescriptor.CreateValidator( Type targetType, Type ownerType, MemberValueAccessBuilder memberValueAccessBuilder, ValidatorFactory validatorFactory) { Validator validator = DoCreateValidator(targetType, ownerType, memberValueAccessBuilder, validatorFactory); validator.Tag = string.IsNullOrEmpty(this.Tag) ? null : this.Tag; validator.MessageTemplate = GetMessageTemplate(); return(validator); }
/// <summary> /// Creates the <see cref="ObjectValidator"/> described by the configuration object. /// </summary> /// <param name="targetType">The type of object that will be validated by the validator.</param> /// <param name="ownerType">The type of the object from which the value to validate is extracted.</param> /// <param name="memberValueAccessBuilder">The <see cref="MemberValueAccessBuilder"/> to use for validators that /// require access to properties.</param> /// <param name="validatorFactory">Factory to use when building nested validators.</param> /// <returns>The created <see cref="Validator"/>.</returns> protected override Validator DoCreateValidator( Type targetType, Type ownerType, MemberValueAccessBuilder memberValueAccessBuilder, ValidatorFactory validatorFactory) { if (this.ValidateActualType) { return new ObjectValidator(validatorFactory, targetRuleset); } else { return new ObjectValidator(targetType, validatorFactory, targetRuleset); } }
/// <summary> /// Creates the <see cref="ObjectValidator"/> described by the configuration object. /// </summary> /// <param name="targetType">The type of object that will be validated by the validator.</param> /// <param name="ownerType">The type of the object from which the value to validate is extracted.</param> /// <param name="memberValueAccessBuilder">The <see cref="MemberValueAccessBuilder"/> to use for validators that /// require access to properties.</param> /// <param name="validatorFactory">Factory to use when building nested validators.</param> /// <returns>The created <see cref="ObjectValidator"/>.</returns> /// <seealso cref="ObjectValidator"/> protected override Validator DoCreateValidator( Type targetType, Type ownerType, MemberValueAccessBuilder memberValueAccessBuilder, ValidatorFactory validatorFactory) { if (this.ValidateActualType) { return(new ObjectValidator(validatorFactory, this.TargetRuleset)); } else { return(new ObjectValidator(targetType, validatorFactory, this.TargetRuleset)); } }
/// <summary> /// Creates the <see cref="AndCompositeValidator"/> described by the configuration object. /// </summary> /// <param name="targetType">The type of object that will be validated by the validator.</param> /// <param name="ownerType">The type of the object from which the value to validate is extracted.</param> /// <param name="memberValueAccessBuilder">The <see cref="MemberValueAccessBuilder"/> to use for validators that /// require access to properties.</param> /// <param name="validatorFactory">Factory to use when building nested validators.</param> /// <returns>The created <see cref="AndCompositeValidator"/>.</returns> /// <seealso cref="AndCompositeValidator"/> protected override Validator DoCreateValidator( Type targetType, Type ownerType, MemberValueAccessBuilder memberValueAccessBuilder, ValidatorFactory validatorFactory) { List <Validator> childValidators = new List <Validator>(this.Validators.Count); foreach (IValidatorDescriptor validatorData in this.Validators) { childValidators.Add(validatorData.CreateValidator(targetType, ownerType, memberValueAccessBuilder, validatorFactory)); } return(new AndCompositeValidator(childValidators.ToArray())); }
/// <summary> /// Creates the <see cref="Validator"/> described by the attribute. /// </summary> /// <param name="targetType">The type of object that will be validated by the validator.</param> /// <param name="ownerType">The type of the object from which the value to validate is extracted.</param> /// <param name="memberValueAccessBuilder">The <see cref="MemberValueAccessBuilder"/> to use for validators that /// require access to properties.</param> /// <returns>The created <see cref="Validator"/>.</returns> protected override Validator DoCreateValidator(Type targetType, Type ownerType, MemberValueAccessBuilder memberValueAccessBuilder) { PropertyInfo propertyInfo = ValidationReflectionHelper.GetProperty(ownerType, this.propertyToCompare, false); if (propertyInfo == null) { throw new InvalidOperationException( string.Format(CultureInfo.CurrentUICulture, Resources.ExceptionPropertyToCompareNotFound, this.propertyToCompare, ownerType.FullName)); } return new PropertyComparisonValidator(memberValueAccessBuilder.GetPropertyValueAccess(propertyInfo), this.comparisonOperator, this.Negated); }
/// <summary> /// Creates the <see cref="ObjectCollectionValidator"/> described by the configuration object. /// </summary> /// <param name="targetType">The type of object that will be validated by the validator.</param> /// <param name="ownerType">The type of the object from which the value to validate is extracted.</param> /// <param name="memberValueAccessBuilder">The <see cref="MemberValueAccessBuilder"/> to use for validators that /// require access to properties.</param> /// <param name="validatorFactory">Factory to use when building nested validators.</param> /// <returns>The created <see cref="Validator"/>.</returns> protected override Validator DoCreateValidator( Type targetType, Type ownerType, MemberValueAccessBuilder memberValueAccessBuilder, ValidatorFactory validatorFactory) { // avoid supplied target type - that's the type of the collection if (this.targetType != null) { return(new ObjectCollectionValidator(this.targetType, validatorFactory, this.targetRuleset)); } else { return(new ObjectCollectionValidator(validatorFactory, this.targetRuleset)); } }
/// <summary> /// Creates the <see cref="ObjectCollectionValidator"/> described by the configuration object. /// </summary> /// <param name="targetType">The type of object that will be validated by the validator.</param> /// <param name="ownerType">The type of the object from which the value to validate is extracted.</param> /// <param name="memberValueAccessBuilder">The <see cref="MemberValueAccessBuilder"/> to use for validators that /// require access to properties.</param> /// <param name="validatorFactory">Factory to use when building nested validators.</param> /// <returns>The created <see cref="ObjectCollectionValidator"/>.</returns> /// <seealso cref="ObjectCollectionValidator"/> protected override Validator DoCreateValidator( Type targetType, Type ownerType, MemberValueAccessBuilder memberValueAccessBuilder, ValidatorFactory validatorFactory) { Type configuredTargetType = this.TargetType; if (configuredTargetType != null) { return new ObjectCollectionValidator(configuredTargetType, validatorFactory, this.TargetRuleset); } else { return new ObjectCollectionValidator(validatorFactory, this.TargetRuleset); } }
/// <summary> /// Creates the <see cref="ObjectCollectionValidator"/> described by the configuration object. /// </summary> /// <param name="targetType">The type of object that will be validated by the validator.</param> /// <param name="ownerType">The type of the object from which the value to validate is extracted.</param> /// <param name="memberValueAccessBuilder">The <see cref="MemberValueAccessBuilder"/> to use for validators that /// require access to properties.</param> /// <param name="validatorFactory">Factory to use when building nested validators.</param> /// <returns>The created <see cref="ObjectCollectionValidator"/>.</returns> /// <seealso cref="ObjectCollectionValidator"/> protected override Validator DoCreateValidator( Type targetType, Type ownerType, MemberValueAccessBuilder memberValueAccessBuilder, ValidatorFactory validatorFactory) { Type configuredTargetType = this.TargetType; if (configuredTargetType != null) { return(new ObjectCollectionValidator(configuredTargetType, validatorFactory, this.TargetRuleset)); } else { return(new ObjectCollectionValidator(validatorFactory, this.TargetRuleset)); } }
/// <summary> /// Creates the <see cref="Validator"/> described by the configuration object. /// </summary> /// <param name="targetType">The type of object that will be validated by the validator.</param> /// <param name="ownerType">The type of the object from which the value to validate is extracted.</param> /// <param name="memberValueAccessBuilder">The <see cref="MemberValueAccessBuilder"/> to use for validators that /// require access to properties.</param> /// <param name="validatorFactory">Factory to use when building nested validators.</param> /// <returns>The created <see cref="Validator"/>.</returns> Validator IValidatorDescriptor.CreateValidator( Type targetType, Type ownerType, MemberValueAccessBuilder memberValueAccessBuilder, ValidatorFactory validatorFactory) { Validator validator = DoCreateValidator(targetType, ownerType, memberValueAccessBuilder, validatorFactory); validator.Tag = string.IsNullOrEmpty(this.Tag) ? null : this.Tag; validator.MessageTemplate = GetMessageTemplate(); return validator; }
/// <summary> /// Creates the <see cref="Validator"/> described by the attribute. /// </summary> /// <param name="targetType">The type of object that will be validated by the validator.</param> /// <param name="ownerType">The type of the object from which the value to validate is extracted.</param> /// <param name="memberValueAccessBuilder">The <see cref="MemberValueAccessBuilder"/> to use for validators that /// require access to properties.</param> /// <param name="validatorFactory">Factory to use when building nested validators.</param> /// <returns>The created <see cref="Validator"/>.</returns> protected override Validator DoCreateValidator(Type targetType, Type ownerType, MemberValueAccessBuilder memberValueAccessBuilder, ValidatorFactory validatorFactory) { PropertyInfo propertyInfo = ValidationReflectionHelper.GetProperty(ownerType, PropertyToCompare, false); if (propertyInfo == null) { throw new InvalidOperationException( string.Format( CultureInfo.CurrentCulture, Translations.ExceptionPropertyToCompareNotFound, PropertyToCompare, ownerType.FullName)); } return(new PropertyComparisonValidator(memberValueAccessBuilder.GetPropertyValueAccess(propertyInfo), ComparisonOperator, Negated)); }
public MockMemberAccessValidatorBuilderFactory(MemberValueAccessBuilder valueAccessBuilder) : base(valueAccessBuilder) { }
/// <summary> /// Creates the <see cref="ObjectCollectionValidator"/> described by the configuration object. /// </summary> /// <param name="targetType">The type of object that will be validated by the validator.</param> /// <param name="ownerType">The type of the object from which the value to validate is extracted.</param> /// <param name="memberValueAccessBuilder">The <see cref="MemberValueAccessBuilder"/> to use for validators that /// require access to properties.</param> /// <param name="validatorFactory">Factory to use when building nested validators.</param> /// <returns>The created <see cref="Validator"/>.</returns> protected override Validator DoCreateValidator( Type targetType, Type ownerType, MemberValueAccessBuilder memberValueAccessBuilder, ValidatorFactory validatorFactory) { // avoid supplied target type - that's the type of the collection if (this.TargetType != null) { return new ObjectCollectionValidator(this.TargetType, validatorFactory, this.targetRuleset); } else { return new ObjectCollectionValidator(validatorFactory, this.targetRuleset); } }
protected override Validator DoCreateValidator(Type targetType, Type ownerType, MemberValueAccessBuilder memberValueAccessBuilder, ValidatorFactory validatorFactory) { return(new ObjectValidator(targetType, validatorFactory, TargetRuleset, KeyFormat)); }
/// <summary> /// Creates the <see cref="Validator"/> described by the configuration object. /// </summary> /// <param name="targetType">The type of object that will be validated by the validator.</param> /// <param name="ownerType">The type of the object from which the value to validate is extracted.</param> /// <param name="memberValueAccessBuilder">The <see cref="MemberValueAccessBuilder"/> to use for validators that /// require access to properties.</param> /// <param name="validatorFactory">Factory to use when building nested validators.</param> /// <returns>The created <see cref="Validator"/>.</returns> /// <remarks> /// The default implementation invokes <see cref="ValidatorAttribute.DoCreateValidator(Type)"/>. Subclasses requiring access to all /// the parameters or this method may override it instead of <see cref="ValidatorAttribute.DoCreateValidator(Type)"/>. /// </remarks> protected virtual Validator DoCreateValidator( Type targetType, Type ownerType, MemberValueAccessBuilder memberValueAccessBuilder, ValidatorFactory validatorFactory) { return DoCreateValidator(targetType); }
protected override Validator DoCreateValidator( Type targetType, Type ownerType, MemberValueAccessBuilder memberValueAccessBuilder, ValidatorFactory validatorFactory) { suppliedValueAccessBuilders.Add(memberValueAccessBuilder); return base.DoCreateValidator(targetType, ownerType, memberValueAccessBuilder, validatorFactory); }
protected override Validator DoCreateValidator(Type targetType, Type ownerType, MemberValueAccessBuilder memberValueAccessBuilder) { var fieldValueAccesses = new List <ValueAccess>(); foreach (var field in fieldsToCompare) { var propertyInfo = ValidationReflectionHelper.GetProperty(ownerType, field); if (propertyInfo == null) { throw new InvalidOperationException(); } fieldValueAccesses.Add(memberValueAccessBuilder.GetPropertyValueAccess(propertyInfo)); } return(new UniqueFieldValueValidator(fieldValueAccesses)); }
public MockMemberAccessValidatorBuilderFactory(MemberValueAccessBuilder valueAccessBuilder) : base(valueAccessBuilder) { }
Validator IValidatorDescriptor.CreateValidator(Type targetType, Type ownerType, MemberValueAccessBuilder memberValueAccessBuilder) { Validator validator = this.DoCreateValidator(targetType, ownerType, memberValueAccessBuilder); validator.Tag = base.Tag; validator.MessageTemplate = base.GetMessageTemplate(); return(validator); }
protected override Validator DoCreateValidator(Type targetType, Type ownerType, MemberValueAccessBuilder memberValueAccessBuilder) { PropertyInfo property = ValidationReflectionHelper.GetProperty(ownerType, this.propertyToCompare, false); if (property == null) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.ExceptionPropertyToCompareNotFound, new object[] { this.propertyToCompare, ownerType.FullName })); } return(new PropertyComparisonValidator(memberValueAccessBuilder.GetPropertyValueAccess(property), this.comparisonOperator, base.Negated)); }
protected virtual Validator DoCreateValidator(Type targetType, Type ownerType, MemberValueAccessBuilder memberValueAccessBuilder) { return(this.DoCreateValidator(targetType)); }