コード例 #1
0
 private void UpdateFlyweight(MemberInfo memberInfo, Type targetType)
 {
     _memberInfo                    = memberInfo;
     _targetType                    = targetType;
     _ignoreNullsAttribute          = ValidationReflectionHelper.ExtractValidationAttribute <IgnoreNullsAttribute>(memberInfo, _ruleset);
     _validatorCompositionAttribute = ValidationReflectionHelper.ExtractValidationAttribute <ValidatorCompositionAttribute>(memberInfo, _ruleset);
 }
コード例 #2
0
        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);
                        }
                    }
                }
            }
        }
コード例 #3
0
 IEnumerable <IValidatedElement> IValidatedType.GetValidatedFields()
 {
     foreach (FieldInfo fieldInfo in
              ((IValidatedElement)this).TargetType.GetFields(BindingFlags.Public | BindingFlags.Instance))
     {
         if (ValidationReflectionHelper.IsValidField(fieldInfo))
         {
             yield return(new ValidationAttributeValidatedElement(fieldInfo));
         }
     }
 }
コード例 #4
0
 IEnumerable <IValidatedElement> IValidatedType.GetValidatedProperties()
 {
     foreach (PropertyInfo propertyInfo in
              ((IValidatedElement)this).TargetType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
     {
         if (ValidationReflectionHelper.IsValidProperty(propertyInfo))
         {
             yield return(new ValidationAttributeValidatedElement(propertyInfo));
         }
     }
 }
コード例 #5
0
        IEnumerable <IValidatedElement> IValidatedType.GetValidatedProperties()
        {
            var flyweight = new MetadataValidatedElement(Ruleset);

            foreach (PropertyInfo propertyInfo in TargetType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                if (ValidationReflectionHelper.IsValidProperty(propertyInfo))
                {
                    flyweight.UpdateFlyweight(propertyInfo);
                    yield return(flyweight);
                }
            }
        }
コード例 #6
0
        IEnumerable <IValidatedElement> IValidatedType.GetValidatedMethods()
        {
            var flyweight = new MetadataValidatedElement(Ruleset);

            foreach (MethodInfo methodInfo in TargetType.GetMethods(BindingFlags.Public | BindingFlags.Instance))
            {
                ParameterInfo[] parameters = methodInfo.GetParameters();

                if (ValidationReflectionHelper.IsValidMethod(methodInfo))
                {
                    flyweight.UpdateFlyweight(methodInfo);
                    yield return(flyweight);
                }
            }
        }
コード例 #7
0
        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)
            });
        }
コード例 #8
0
        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);
                }
            }
        }
コード例 #9
0
 public void UpdateFlyweight(ParameterInfo parameterInfo)
 {
     _parameterInfo                 = parameterInfo;
     _ignoreNullsAttribute          = ValidationReflectionHelper.ExtractValidationAttribute <IgnoreNullsAttribute>(parameterInfo, string.Empty);
     _validatorCompositionAttribute = ValidationReflectionHelper.ExtractValidationAttribute <ValidatorCompositionAttribute>(parameterInfo, string.Empty);
 }