IEnumerable <MethodInfo> IValidatedType.GetSelfValidationMethods() { Type type = TargetType; if (ValidationReflectionHelper.GetCustomAttributes(type, typeof(HasSelfValidationAttribute), false).Length == 0) { yield break; // no self validation for the current type, ignore type } foreach (MethodInfo methodInfo in type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { bool hasReturnType = methodInfo.ReturnType != typeof(void); ParameterInfo[] parameters = methodInfo.GetParameters(); if (!hasReturnType && parameters.Length == 1 && parameters[0].ParameterType == typeof(ValidationResults)) { foreach (SelfValidationAttribute attribute in ValidationReflectionHelper.GetCustomAttributes(methodInfo, typeof(SelfValidationAttribute), false)) { if (Ruleset.Equals(attribute.Ruleset)) { yield return(methodInfo); } } } } }
IEnumerable <IValidatorDescriptor> IValidatedElement.GetValidatorDescriptors() { var attributes = ValidationReflectionHelper.GetCustomAttributes(_memberInfo, typeof(ValidationAttribute), true) .Cast <ValidationAttribute>() .Where(a => !typeof(BaseValidationAttribute).IsAssignableFrom(a.GetType())) .ToArray(); if (attributes.Length == 0) { return(new IValidatorDescriptor[0]); } return(new IValidatorDescriptor[] { new ValidationAttributeValidatorDescriptor(attributes) }); }
IEnumerable <IValidatorDescriptor> IValidatedElement.GetValidatorDescriptors() { if (_memberInfo == null) { yield break; } foreach (var attribute in ValidationReflectionHelper.GetCustomAttributes(_memberInfo, typeof(ValidatorAttribute), false)) { var validationAttribute = attribute as ValidatorAttribute; if (validationAttribute == null) { continue; } if (_ruleset.Equals(validationAttribute.Ruleset)) { yield return(validationAttribute); } } }