PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties() { // get model properties List <PropertyDescriptor> properties = new List <PropertyDescriptor>(); foreach (PropertyDescriptor modelPropertyDescriptor in ModelUtilities.WrapProperties(this)) { properties.Add(modelPropertyDescriptor); } // try to see if there are pseudo builtin properties for this type. AttachedPropertiesService AttachedPropertiesService = this.modelTreeManager.Context.Services.GetService <AttachedPropertiesService>(); if (AttachedPropertiesService != null) { var nonBrowsableAttachedProperties = from attachedProperty in AttachedPropertiesService.GetAttachedProperties(this.itemType) where (!attachedProperty.IsBrowsable && !attachedProperty.IsVisibleToModelItem) select attachedProperty; foreach (AttachedProperty AttachedProperty in nonBrowsableAttachedProperties) { properties.Add(new AttachedPropertyDescriptor(AttachedProperty, this)); } } return(new PropertyDescriptorCollection(properties.ToArray(), true)); }
PropertyDescriptorCollection GetPropertyDescriptors() { PropertyDescriptorCollection propertyDescriptors = PropertyDescriptorCollection.Empty; try { object instance = parent.GetCurrentValue(); if (instance != null) { if (!(instance is ICustomTypeDescriptor)) { Type instanceType = instance.GetType(); if (instanceType.IsValueType) { propertyDescriptors = TypeDescriptor.GetProvider(instanceType).GetTypeDescriptor(instanceType).GetProperties(); } else { propertyDescriptors = TypeDescriptor.GetProvider(instance).GetTypeDescriptor(instance).GetProperties(); } } else { propertyDescriptors = TypeDescriptor.GetProperties(instance); } } // Add browsable attached properties AttachedPropertiesService AttachedPropertiesService = this.parent.GetEditingContext().Services.GetService <AttachedPropertiesService>(); if (AttachedPropertiesService != null) { var browsableAttachedProperties = from attachedProperty in AttachedPropertiesService.GetAttachedProperties(this.parent.ItemType) where (attachedProperty.IsBrowsable || attachedProperty.IsVisibleToModelItem) select new AttachedPropertyDescriptor(attachedProperty, this.parent); List <PropertyDescriptor> mergedProperties = new List <PropertyDescriptor>(); foreach (PropertyDescriptor propertyDescriptor in propertyDescriptors) { mergedProperties.Add(propertyDescriptor); } propertyDescriptors = new PropertyDescriptorCollection(mergedProperties.Concat(browsableAttachedProperties).ToArray(), true); } } catch (FileNotFoundException e) { EditingContext context = parent.GetEditingContext(); if (context.Items.GetValue <ErrorItem>() == null) { context.Items.SetValue(new ErrorItem { Message = e.Message, Details = e.ToString() }); } } return(propertyDescriptors); }