/// <summary> /// Gets a validator for the specified target type. /// </summary> /// <param name="targetType">The target type.</param> /// <returns>The <see cref="IValidator" /> for the specified type or <c>null</c> if no validator is available for the specified type.</returns> /// <exception cref="ArgumentNullException">The <paramref name="targetType" /> is <c>null</c>.</exception> /// <remarks>If there are more than once validator provider and they retrieve more than once validator all of these will be aggregated into a single <see cref="CompositeValidator" />.</remarks> protected override IValidator GetValidator(Type targetType) { IValidator validator; lock (_syncObj) { IList <IValidator> discoveredValidators = _validatorProviders.Select(validatorProvider => validatorProvider.GetValidator(targetType)).Where(discoveredValidator => discoveredValidator != null).ToList(); if (discoveredValidators.Count > 1) { var composite = new CompositeValidator(); foreach (IValidator discoveredValidator in discoveredValidators) { composite.Add(discoveredValidator); } validator = composite; } else { validator = discoveredValidators.FirstOrDefault(); } } return(validator); }
/// <summary> /// Gets a validator for the specified target type. /// </summary> /// <param name="targetType">The target type.</param> /// <returns>The <see cref="IValidator" /> for the specified type or <c>null</c> if no validator is available for the specified type.</returns> /// <exception cref="ArgumentNullException">The <paramref name="targetType" /> is <c>null</c>.</exception> /// <remarks>If there are more than once validator provider and they retrieve more than once validator all of these will be aggregated into a single <see cref="CompositeValidator" />.</remarks> protected override IValidator GetValidator(Type targetType) { IValidator validator; lock (_syncObj) { IList<IValidator> discoveredValidators = _validatorProviders.Select(validatorProvider => validatorProvider.GetValidator(targetType)).Where(discoveredValidator => discoveredValidator != null).ToList(); if (discoveredValidators.Count > 1) { var composite = new CompositeValidator(); foreach (var discoveredValidator in discoveredValidators) { composite.Add(discoveredValidator); } validator = composite; } else { validator = discoveredValidators.FirstOrDefault(); } } return validator; }