Beispiel #1
0
        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return(true);
            }
            ToolStripItemDesignerAvailabilityAttribute attribute = obj as ToolStripItemDesignerAvailabilityAttribute;

            return((attribute != null) && (attribute.ItemAdditionVisibility == this.visibility));
        }
 public static System.Type[] GetCustomItemTypes(IComponent component, ITypeDiscoveryService discoveryService)
 {
     if (discoveryService != null)
     {
         ICollection types = discoveryService.GetTypes(toolStripItemType, false);
         ToolStripItemDesignerAvailability designerVisibility = GetDesignerVisibility(GetToolStripFromComponent(component));
         System.Type[] standardItemTypes = GetStandardItemTypes(component);
         if (designerVisibility != ToolStripItemDesignerAvailability.None)
         {
             ArrayList list = new ArrayList(types.Count);
             foreach (System.Type type in types)
             {
                 if ((type.IsAbstract || (!type.IsPublic && !type.IsNestedPublic)) || (type.ContainsGenericParameters || (type.GetConstructor(new System.Type[0]) == null)))
                 {
                     continue;
                 }
                 ToolStripItemDesignerAvailabilityAttribute attribute = (ToolStripItemDesignerAvailabilityAttribute)TypeDescriptor.GetAttributes(type)[typeof(ToolStripItemDesignerAvailabilityAttribute)];
                 if ((attribute != null) && ((attribute.ItemAdditionVisibility & designerVisibility) == designerVisibility))
                 {
                     bool flag = false;
                     foreach (System.Type type2 in standardItemTypes)
                     {
                         if (type2 == type)
                         {
                             flag = true;
                             break;
                         }
                     }
                     if (!flag)
                     {
                         list.Add(type);
                     }
                 }
             }
             if (list.Count > 0)
             {
                 System.Type[] array = new System.Type[list.Count];
                 list.CopyTo(array, 0);
                 CustomToolStripItemCount = list.Count;
                 return(array);
             }
         }
     }
     CustomToolStripItemCount = 0;
     return(new System.Type[0]);
 }
Beispiel #3
0
        public static Type[] GetCustomItemTypes(IComponent component, ITypeDiscoveryService discoveryService)
        {
            if (discoveryService != null)
            {
                // fish out all types which derive from toolstrip item
                ICollection itemTypes = discoveryService.GetTypes(s_toolStripItemType, false /*excludeGlobalTypes*/);
                ToolStrip   toolStrip = GetToolStripFromComponent(component);
                // determine the value of the visibility attribute which matches the current toolstrip type.
                ToolStripItemDesignerAvailability currentToolStripVisibility = GetDesignerVisibility(toolStrip);
                Debug.Assert(currentToolStripVisibility != ToolStripItemDesignerAvailability.None, "Why is GetDesignerVisibility returning None?");
                // fish out the ones we've already listed.
                Type[] stockItemTypeList = GetStandardItemTypes(component);
                if (currentToolStripVisibility != ToolStripItemDesignerAvailability.None)
                {
                    ArrayList createableTypes = new ArrayList(itemTypes.Count);
                    foreach (Type t in itemTypes)
                    {
                        if (t.IsAbstract)
                        {
                            continue;
                        }
                        if (!t.IsPublic && !t.IsNestedPublic)
                        {
                            continue;
                        }
                        if (t.ContainsGenericParameters)
                        {
                            continue;
                        }
                        // Check if we have public constructor...
                        ConstructorInfo ctor = t.GetConstructor(new Type[0]);
                        if (ctor == null)
                        {
                            continue;
                        }

                        // if the visibility matches the current toolstrip type,  add it to the list of possible types to create.
                        ToolStripItemDesignerAvailabilityAttribute visiblityAttribute = (ToolStripItemDesignerAvailabilityAttribute)TypeDescriptor.GetAttributes(t)[typeof(ToolStripItemDesignerAvailabilityAttribute)];
                        if (visiblityAttribute != null && ((visiblityAttribute.ItemAdditionVisibility & currentToolStripVisibility) == currentToolStripVisibility))
                        {
                            bool isStockType = false;
                            // PERF: consider a dictionary - but this list will usually be 3-7 items.
                            foreach (Type stockType in stockItemTypeList)
                            {
                                if (stockType == t)
                                {
                                    isStockType = true;
                                    break;
                                }
                            }
                            if (!isStockType)
                            {
                                createableTypes.Add(t);
                            }
                        }
                    }

                    if (createableTypes.Count > 0)
                    {
                        Type[] createableTypesArray = new Type[createableTypes.Count];
                        createableTypes.CopyTo(createableTypesArray, 0);
                        s_customToolStripItemCount = createableTypes.Count;
                        return(createableTypesArray);
                    }
                }
            }
            s_customToolStripItemCount = 0;
            return(new Type[0]);
        }