コード例 #1
0
 private void UpdateFlyweight(MemberInfo memberInfo, Type targetType)
 {
     this.memberInfo                    = memberInfo;
     this.targetType                    = targetType;
     this.ignoreNullsAttribute          = ValidationReflectionHelper.ExtractValidationAttribute <IgnoreNullsAttribute>(memberInfo, this.ruleset);
     this.validatorCompositionAttribute = ValidationReflectionHelper.ExtractValidationAttribute <ValidatorCompositionAttribute>(memberInfo, this.ruleset);
 }
コード例 #2
0
        public static PropertyInfo GetProperty(Type type, string propertyName, bool throwIfInvalid)
        {
            if (string.IsNullOrEmpty(propertyName))
            {
                throw new ArgumentNullException("propertyName");
            }
            PropertyInfo property = type.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public);

            if (ValidationReflectionHelper.IsValidProperty(property))
            {
                return(property);
            }
            if (throwIfInvalid)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.ExceptionInvalidProperty, new object[]
                {
                    propertyName,
                    type.FullName
                }));
            }
            return(null);
        }
コード例 #3
0
        public static MethodInfo GetMethod(Type type, string methodName, bool throwIfInvalid)
        {
            if (string.IsNullOrEmpty(methodName))
            {
                throw new ArgumentNullException("methodName");
            }
            MethodInfo method = type.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public, null, Type.EmptyTypes, null);

            if (ValidationReflectionHelper.IsValidMethod(method))
            {
                return(method);
            }
            if (throwIfInvalid)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.ExceptionInvalidMethod, new object[]
                {
                    methodName,
                    type.FullName
                }));
            }
            return(null);
        }
コード例 #4
0
        public static FieldInfo GetField(Type type, string fieldName, bool throwIfInvalid)
        {
            if (string.IsNullOrEmpty(fieldName))
            {
                throw new ArgumentNullException("fieldName");
            }
            FieldInfo field = type.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public);

            if (ValidationReflectionHelper.IsValidField(field))
            {
                return(field);
            }
            if (throwIfInvalid)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.ExceptionInvalidField, new object[]
                {
                    fieldName,
                    type.FullName
                }));
            }
            return(null);
        }
コード例 #5
0
        IEnumerable <IValidatedElement> IValidatedType.GetValidatedProperties()
        {
            MetadataValidatedElement metadataValidatedElement = new MetadataValidatedElement(base.Ruleset);

            try
            {
                PropertyInfo[] properties = base.TargetType.GetProperties(BindingFlags.Instance | BindingFlags.Public);
                for (int i = 0; i < properties.Length; i++)
                {
                    PropertyInfo propertyInfo = properties[i];
                    if (ValidationReflectionHelper.IsValidProperty(propertyInfo))
                    {
                        metadataValidatedElement.UpdateFlyweight(propertyInfo);
                        yield return(metadataValidatedElement);
                    }
                }
            }
            finally
            {
            }
            yield break;
        }
コード例 #6
0
        IEnumerable <IValidatedElement> IValidatedType.GetValidatedMethods()
        {
            MetadataValidatedElement metadataValidatedElement = new MetadataValidatedElement(base.Ruleset);

            try
            {
                MethodInfo[] methods = base.TargetType.GetMethods(BindingFlags.Instance | BindingFlags.Public);
                for (int i = 0; i < methods.Length; i++)
                {
                    MethodInfo methodInfo = methods[i];
                    methodInfo.GetParameters();
                    if (ValidationReflectionHelper.IsValidMethod(methodInfo))
                    {
                        metadataValidatedElement.UpdateFlyweight(methodInfo);
                        yield return(metadataValidatedElement);
                    }
                }
            }
            finally
            {
            }
            yield break;
        }
コード例 #7
0
 public void UpdateFlyweight(ParameterInfo parameterInfo)
 {
     this.parameterInfo                 = parameterInfo;
     this.ignoreNullsAttribute          = ValidationReflectionHelper.ExtractValidationAttribute <IgnoreNullsAttribute>(parameterInfo, string.Empty);
     this.validatorCompositionAttribute = ValidationReflectionHelper.ExtractValidationAttribute <ValidatorCompositionAttribute>(parameterInfo, string.Empty);
 }