public PropertyDescriptorCollection GetProperties(Attribute[] attributes) { if (_propertyDescriptorCollection == null) { var collection = _wrappedCustomTypeDescriptor.GetProperties(attributes); _propertyDescriptorCollection = new PropertyDescriptorCollection(null); foreach (PropertyDescriptor propertyDescriptor in collection) { // Check if the property descriptor is ours. var customPropertyDescriptor = propertyDescriptor as CustomPropertyDescriptor; if (customPropertyDescriptor != null) { // Since we are changing the property descriptor type, we need to build propertyDescriptorToOwner map, // so that the right value is returned when Visual-Studio calls GetPropertyOwner. var linkedPropertyDescriptor = new LinkedPropertyDescriptor(customPropertyDescriptor, _contextItem); var propertyOwner = _wrappedCustomTypeDescriptor.GetPropertyOwner(propertyDescriptor); Debug.Assert(propertyOwner != null, "Could not find property owner for " + propertyDescriptor.Name); if (propertyOwner != null) { _propertyDescriptorToOwner.Add(linkedPropertyDescriptor, propertyOwner); _propertyDescriptorCollection.Add(linkedPropertyDescriptor); } } else { _propertyDescriptorCollection.Add(propertyDescriptor); } } } return(_propertyDescriptorCollection); }
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) { if (_propertyDescriptorCollection == null) { var collection = _wrappedCustomTypeDescriptor.GetProperties(attributes); _propertyDescriptorCollection = new PropertyDescriptorCollection(null); foreach (PropertyDescriptor propertyDescriptor in collection) { // Check if the property descriptor is ours. var customPropertyDescriptor = propertyDescriptor as CustomPropertyDescriptor; if (customPropertyDescriptor != null) { // Since we are changing the property descriptor type, we need to build propertyDescriptorToOwner map, // so that the right value is returned when Visual-Studio calls GetPropertyOwner. var linkedPropertyDescriptor = new LinkedPropertyDescriptor(customPropertyDescriptor, _contextItem); var propertyOwner = _wrappedCustomTypeDescriptor.GetPropertyOwner(propertyDescriptor); Debug.Assert(propertyOwner != null, "Could not find property owner for " + propertyDescriptor.Name); if (propertyOwner != null) { _propertyDescriptorToOwner.Add(linkedPropertyDescriptor, propertyOwner); _propertyDescriptorCollection.Add(linkedPropertyDescriptor); } } else { _propertyDescriptorCollection.Add(propertyDescriptor); } } } return _propertyDescriptorCollection; }