private void CreateBindings() { bindings = new PropertyBindingCollection(); ManagedPropertiesService svc = (ManagedPropertiesService)component.Site.GetService(typeof(ManagedPropertiesService)); if (svc != null) { PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(component, new Attribute[] { BrowsableAttribute.Yes }); for (int i = 0; i < properties.Count; i++) { PropertyDescriptor prop = properties[i]; if (prop.DesignTimeOnly) { continue; } if (prop.IsReadOnly) { continue; } if (prop.Attributes.Contains(DesignerSerializationVisibilityAttribute.Hidden)) { continue; } // don't show the ComponentSettings property - it can't be managed! if (prop.PropertyType == typeof(ComponentSettings)) { continue; } if (!ManagedPropertiesService.IsTypeSupported(prop.PropertyType)) { continue; } PropertyBinding binding = svc.Bindings[component, prop]; if (binding == null) { binding = new PropertyBinding(host); binding.Component = component; binding.Property = prop; binding.Reset(); } else { binding = (PropertyBinding)binding.Clone(); } bindings.Add(binding); } } }
/// <include file='doc\ComponentSettingsConverter.uex' path='docs/doc[@for="ComponentSettingsConverter.GetProperties"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { ComponentSettings compSettings = (ComponentSettings)value; PropertyBindingCollection bindings = compSettings.Bindings.GetBindingsForComponent(compSettings.Component); ArrayList props = new ArrayList(); // go through all the properties on the component and see if they have the "show me" attribute. // also check to see if the propert has already been bound. IComponent component = compSettings.Component; IDesignerHost host = (IDesignerHost)component.Site.GetService(typeof(IDesignerHost)); PropertyDescriptorCollection componentProps = TypeDescriptor.GetProperties(component); for (int i = 0; i < componentProps.Count; i++) { PropertyDescriptor prop = componentProps[i]; if (!prop.IsReadOnly && ManagedPropertiesService.IsTypeSupported(prop.PropertyType)) { bool recommended = ((RecommendedAsConfigurableAttribute)prop.Attributes[typeof(RecommendedAsConfigurableAttribute)]).RecommendedAsConfigurable; PropertyBinding binding = bindings[component, prop]; if (recommended || (binding != null && binding.Bound)) { props.Add(new BindingPropertyDescriptor(compSettings, prop)); } } } // add the (Advanced...) property props.Add(new AdvancedPropertyDescriptor(compSettings)); PropertyDescriptor[] propsArray = new PropertyDescriptor[props.Count]; for (int i = 0; i < props.Count; i++) { propsArray[i] = (PropertyDescriptor)props[i]; } return(new PropertyDescriptorCollection(propsArray)); }