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);
        }
Ejemplo n.º 2
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;
        }