Exemple #1
0
        public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            int n = 1;

            Attribute[] attrs = new Attribute[4];
            if (_scope == null)
            {
                attrs[0] = new ComponentReferenceSelectorTypeAttribute(typeof(IComponent));
            }
            else
            {
                attrs[0] = new ComponentReferenceSelectorTypeAttribute(_scope);
            }
            attrs[1] = new EditorAttribute(typeof(ComponentReferenceSelector), typeof(UITypeEditor));
            attrs[2] = new RefreshPropertiesAttribute(RefreshProperties.All);
            attrs[3] = new DescriptionAttribute("Component name");
            List <PropertyDescriptor> ps = new List <PropertyDescriptor>();

            foreach (string ic in this)
            {
                Attribute[] attrs0 = new Attribute[4];
                if (_scope == null)
                {
                    attrs0[0] = new ComponentReferenceSelectorTypeAttribute(typeof(IComponent));
                }
                else
                {
                    attrs0[0] = new ComponentReferenceSelectorTypeAttribute(_scope);
                }
                attrs0[1] = new EditorAttribute(typeof(ComponentReferenceSelector), typeof(UITypeEditor));
                attrs0[2] = new RefreshPropertiesAttribute(RefreshProperties.All);
                attrs0[3] = new XmlIgnoreAttribute();
                PropertyDescriptorComponent p = new PropertyDescriptorComponent(
                    string.Format(CultureInfo.InvariantCulture, "Item{0}", n), ic, this, attrs0);
                ps.Add(p);
                n++;
            }
            ps.Add(new PropertyDescriptorComponent(string.Format(CultureInfo.InvariantCulture, "Item{0}", n), null, this, attrs));
            return(new PropertyDescriptorCollection(ps.ToArray()));
        }
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && provider != null)
     {
         IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if (edSvc != null)
         {
             Type scopeType    = null;
             Type scopeTypeWeb = null;
             if (context.PropertyDescriptor.Attributes != null)
             {
                 foreach (Attribute a in context.PropertyDescriptor.Attributes)
                 {
                     ComponentReferenceSelectorTypeAttribute cr = a as ComponentReferenceSelectorTypeAttribute;
                     if (cr != null)
                     {
                         scopeType = cr.ScopeType;
                     }
                     else
                     {
                         ComponentReferenceSelectorTypeWebAttribute crw = a as ComponentReferenceSelectorTypeWebAttribute;
                         if (crw != null)
                         {
                             scopeTypeWeb = crw.ScopeType;
                         }
                     }
                 }
             }
             if (scopeType != null || scopeTypeWeb != null)
             {
                 bool       bForName = false;
                 IComponent ic       = context.Instance as IComponent;
                 if (ic == null)
                 {
                     IClassId icid = context.Instance as IClassId;
                     if (icid != null)
                     {
                         ic = icid.ObjectInstance as IComponent;
                     }
                 }
                 if (ic == null)
                 {
                     CollectionComponentNames cc = context.Instance as CollectionComponentNames;
                     if (cc != null)
                     {
                         ic       = cc.Owner;
                         bForName = true;
                     }
                 }
                 if (ic != null && ic.Site != null)
                 {
                     ComponentList list = new ComponentList(edSvc);
                     list.Items.Add(string.Empty);
                     foreach (IComponent c in ic.Site.Container.Components)
                     {
                         Type t = c.GetType();
                         if (scopeType != null && scopeType.IsAssignableFrom(t))
                         {
                             list.Items.Add(c);
                         }
                         else if (scopeTypeWeb != null && scopeTypeWeb.IsAssignableFrom(t))
                         {
                             list.Items.Add(c);
                         }
                     }
                     if (list.Items.Count > 0)
                     {
                         edSvc.DropDownControl(list);
                         if (list.SelectedObj != null)
                         {
                             if (typeof(string).Equals(list.SelectedObj.GetType()))
                             {
                                 value = null;
                             }
                             else
                             {
                                 if (bForName)
                                 {
                                     IComponent ic2 = list.SelectedObj as IComponent;
                                     if (ic2 != null && ic2.Site != null)
                                     {
                                         value = ic2.Site.Name;
                                     }
                                 }
                                 else
                                 {
                                     value = list.SelectedObj;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return(value);
 }