Esempio n. 1
0
        IEnumerable <MethodInfo> IValidatedType.GetSelfValidationMethods()
        {
            Type type = this.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 (this.Ruleset.Equals(attribute.Ruleset))
                        {
                            yield return(methodInfo);

                            continue;   // done with current method
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        IEnumerable <IValidatorDescriptor> IValidatedElement.GetValidatorDescriptors()
        {
            if (this.memberInfo == null)
            {
                yield break;
            }

            foreach (ValidatorAttribute attribute in
                     ValidationReflectionHelper.GetCustomAttributes(this.memberInfo, typeof(ValidatorAttribute), false))
            {
                if (this.ruleset.Equals(attribute.Ruleset))
                {
                    yield return(attribute);
                }
            }
        }
        IEnumerable <IValidatorDescriptor> IValidatedElement.GetValidatorDescriptors()
        {
            var attributes =
                ValidationReflectionHelper
                .GetCustomAttributes(this.memberInfo, typeof(ValidationAttribute), true)
                .Cast <ValidationAttribute>()
                .Where(a => !typeof(BaseValidationAttribute).IsAssignableFrom(a.GetType()))
                .ToArray();

            if (attributes.Length == 0)
            {
                return(new IValidatorDescriptor[0]);
            }
            else
            {
                return(new IValidatorDescriptor[]
                {
                    new ValidationAttributeValidatorDescriptor(attributes)
                });
            }
        }