/// <summary> /// Crée la collection des descripteurs de propriétés. /// </summary> /// <param name="properties">PropertyDescriptors.</param> /// <param name="defaultProperty">Propriété par défaut.</param> /// <param name="beanType">Type du bean.</param> /// <param name="metadataProperties">Métadonnées.</param> /// <returns>Collection.</returns> private static BeanPropertyDescriptorCollection CreateCollection(PropertyDescriptorCollection properties, PropertyDescriptor defaultProperty, Type beanType, PropertyDescriptorCollection metadataProperties) { BeanPropertyDescriptorCollection coll = new BeanPropertyDescriptorCollection(beanType); for (int i = 0; i < properties.Count; i++) { PropertyDescriptor property = properties[i]; KeyAttribute keyAttr = (KeyAttribute)property.Attributes[typeof(KeyAttribute)]; DisplayAttribute displayAttr = (DisplayAttribute)property.Attributes[typeof(DisplayAttribute)]; ReferencedTypeAttribute attr = (ReferencedTypeAttribute)property.Attributes[typeof(ReferencedTypeAttribute)]; ColumnAttribute colAttr = (ColumnAttribute)property.Attributes[typeof(ColumnAttribute)]; DomainAttribute domainAttr = (DomainAttribute)property.Attributes[typeof(DomainAttribute)]; RequiredAttribute requiredAttr = (RequiredAttribute)property.Attributes[typeof(RequiredAttribute)]; TranslatableAttribute translatableAttr = (TranslatableAttribute)property.Attributes[typeof(TranslatableAttribute)]; Type[] genericArgumentArray = beanType.GetGenericArguments(); string display = null; if (displayAttr != null) { if (displayAttr.ResourceType != null && displayAttr.Name != null) { Dictionary <string, PropertyInfo> resourceProperties; if (!_resourceTypeMap.TryGetValue(displayAttr.ResourceType, out resourceProperties)) { resourceProperties = new Dictionary <string, PropertyInfo>(); _resourceTypeMap[displayAttr.ResourceType] = resourceProperties; foreach (PropertyInfo p in displayAttr.ResourceType.GetProperties(BindingFlags.Public | BindingFlags.Static)) { resourceProperties.Add(p.Name, p); } } display = resourceProperties[displayAttr.Name].GetValue(null, null).ToString(); } else { display = displayAttr.Name; } } string memberName = (colAttr == null) ? null : colAttr.Name; bool isPrimaryKey = keyAttr != null; bool isRequired = requiredAttr != null; bool isTranslatable = translatableAttr != null; string domainName = (domainAttr == null) ? null : domainAttr.Name; bool isDefault = property.Equals(defaultProperty) || (DefaultPropertyDefaultName.Equals(property.Name) && defaultProperty == null); Type referenceType = attr == null ? null : attr.ReferenceType; //// Type dtoType = genericArgumentArray.Length > 0 ? genericArgumentArray[0] : beanType; bool isBrowsable = property.IsBrowsable; bool isReadonly = property.IsReadOnly; // Traitement des métadonnées. if (metadataProperties != null) { PropertyDescriptor metadata = metadataProperties[property.Name]; if (metadata != null) { if (!metadata.IsBrowsable) { isBrowsable = false; } if (metadata.Attributes[typeof(RequiredAttribute)] != null) { isRequired = true; } if (metadata.Attributes[typeof(TranslatableAttribute)] != null) { isTranslatable = true; } ReadOnlyAttribute readonlyAttr = (ReadOnlyAttribute)metadata.Attributes[typeof(ReadOnlyAttribute)]; if (readonlyAttr != null && readonlyAttr.IsReadOnly) { isReadonly = true; } } } BeanPropertyDescriptor description = new BeanPropertyDescriptor( property.Name, memberName, property.PropertyType, display, domainName, isPrimaryKey, isDefault, isRequired, referenceType, isReadonly, isBrowsable, isTranslatable); if (domainName != null) { DomainManager.Instance.GetDomain(description); } coll.Add(description); } return(coll); }