private PropertyDescriptorCollection GetPropertiesWithMetadata(PropertyDescriptorCollection originalCollection) { if (AssociatedMetadataType == null) { return(originalCollection); } bool customDescriptorsCreated = false; List <PropertyDescriptor> tempPropertyDescriptors = new List <PropertyDescriptor>(); foreach (PropertyDescriptor propDescriptor in originalCollection) { Attribute[] newMetadata = TypeDescriptorCache.GetAssociatedMetadata(AssociatedMetadataType, propDescriptor.Name); PropertyDescriptor descriptor = propDescriptor; if (newMetadata.Length > 0) { // Create a metadata descriptor that wraps the property descriptor descriptor = new MetadataPropertyDescriptorWrapper(propDescriptor, newMetadata); customDescriptorsCreated = true; } tempPropertyDescriptors.Add(descriptor); } if (customDescriptorsCreated) { return(new PropertyDescriptorCollection(tempPropertyDescriptors.ToArray(), true)); } return(originalCollection); }
private PropertyDescriptorCollection GetPropertiesWithMetadata(PropertyDescriptorCollection originalCollection) { if (AssociatedMetadataType == null) { return originalCollection; } bool customDescriptorsCreated = false; List<PropertyDescriptor> tempPropertyDescriptors = new List<PropertyDescriptor>(); foreach (PropertyDescriptor propDescriptor in originalCollection) { Attribute[] newMetadata = TypeDescriptorCache.GetAssociatedMetadata(AssociatedMetadataType, propDescriptor.Name); PropertyDescriptor descriptor = propDescriptor; if (newMetadata.Length > 0) { // Create a metadata descriptor that wraps the property descriptor descriptor = new MetadataPropertyDescriptorWrapper(propDescriptor, newMetadata); customDescriptorsCreated = true; } tempPropertyDescriptors.Add(descriptor); } if (customDescriptorsCreated) { return new PropertyDescriptorCollection(tempPropertyDescriptors.ToArray(), true); } return originalCollection; }