/// <summary> /// Init validationproxy. /// </summary> private void _InitValidation() { _validationProxy = new PropertyValidationProxy(); _validationProxy.ProvidesCustomValueConversion = false; _validationProxy.SpecificationSource = ValidationSpecificationSource.Attributes; _validationProxy.ValidatedType = GetType(); _validationProxy.Ruleset = ""; }
/// <summary> /// Creates validators for objects of the specified type and it's properties. /// </summary> /// <param name="objectType">The type of objects to create validators for.</param> /// <returns>An instance of the validators container with validators for the specified /// type.</returns> private static ValidatorsContainer _CreateValidators(Type objectType) { Debug.Assert(objectType != null); var propertyFlags = BindingFlags.Instance | BindingFlags.Public; var validateableProperties = from propertyInfo in objectType.GetProperties(propertyFlags) where propertyInfo.GetCustomAttributes<BaseValidationAttribute>().Any() select propertyInfo; var propertyValidators = new Dictionary<string, Validator>(); foreach (var propertyInfo in validateableProperties) { var validationProxy = new PropertyValidationProxy { ProvidesCustomValueConversion = false, SpecificationSource = ValidationSpecificationSource.Attributes, ValidatedType = objectType, Ruleset = string.Empty, ValidatedPropertyName = propertyInfo.Name, }; var validationHelper = new ValidationIntegrationHelper(validationProxy); var validator = validationHelper.GetValidator(); propertyValidators.Add(propertyInfo.Name, validator); } var objectValidator = ValidationFactory.CreateValidator(objectType); return new ValidatorsContainer { ObjectValidator = objectValidator, PropertyValidators = propertyValidators, }; }