private TypeInformation CreateTypeInformation(Type type) { TypeInformation info = new TypeInformation(); ICustomTypeDescriptor typeDescriptor = new AssociatedMetadataTypeTypeDescriptionProvider(type).GetTypeDescriptor(type); info.TypeDescriptor = typeDescriptor; info.Prototype = CreateMetadataPrototype(AsAttributes(typeDescriptor.GetAttributes()), containerType: null, modelType: type, propertyName: null); Dictionary <string, PropertyInformation> properties = new Dictionary <string, PropertyInformation>(); foreach (PropertyDescriptor property in typeDescriptor.GetProperties()) { // Avoid re-generating a property descriptor if one has already been generated for the property name if (!properties.ContainsKey(property.Name)) { if (property.Attributes.OfType <IUnvalidatable>().Any()) { continue; } properties.Add(property.Name, CreatePropertyInformation(type, property)); } } info.Properties = properties; return(info); }
private static List <IDataAnnotationsValidatorAdapter> GetAdapters(Type type) { var typeDescriptor = new AssociatedMetadataTypeTypeDescriptionProvider(type).GetTypeDescriptor(type); var adapters = GetAdapters(null, type, typeDescriptor.GetAttributes().OfType <ValidationAttribute>()); var propertyDescriptors = typeDescriptor.GetProperties(); foreach (PropertyDescriptor property in propertyDescriptors) { adapters.AddRange(GetAdapters(property, property.PropertyType, property.Attributes.OfType <ValidationAttribute>())); } return(adapters); }