public static bool TryCollectValidationDetails(Type itemType, out PropertyValidatorCollection typeAttributeCollection)
        {
            if (itemType == null)
            {
                throw new ArgumentNullException(nameof(itemType));
            }

            typeAttributeCollection = null;

            // Collect the validation interfaces from the type.
            var validationInterfaces = itemType.GetInterfaces()
                                       .Where(t => t.GetCustomAttributes(typeof(ValidationContractAttribute), true).Count() == 1)
                                       .Union(new[] { itemType });

            foreach (Type validationType in validationInterfaces)
            {
                PropertyInfo[] properties = validationType.GetProperties();

                // Walk through the properties for the object.
                foreach (PropertyInfo property in properties)
                {
                    var attributes = property.GetCustomAttributes(typeof(PropertyValidatorAttribute), true).Cast <PropertyValidatorAttribute>();

                    // If the property has an attribute associated then
                    foreach (PropertyValidatorAttribute attribute in attributes)
                    {
                        // Associate the attribute with the property info.
                        attribute.Configure(property);

                        if (typeAttributeCollection == null)
                        {
                            typeAttributeCollection = new PropertyValidatorCollection();
                        }

                        typeAttributeCollection.AddPropertyValidator(attribute);
                    }
                }
            }

            return(typeAttributeCollection != null);
        }
 public static PropertyValidatorCollection CreatePropertyValidator(this Type type)
 {
     return(PropertyValidatorCollection.CollectFrom(type));
 }
 public static bool TryCollectValidationDetails <T>(out PropertyValidatorCollection typeAttributeCollection)
 {
     return(TryCollectValidationDetails(typeof(T), out typeAttributeCollection));
 }