2 // System.ComponentModel.MemberDescriptor.cs
5 // Miguel de Icaza (miguel@ximian.com)
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
8 // (C) Ximian, Inc. http://www.ximian.com
9 // (C) 2003 Andreas Nahr
13 using System.Collections;
14 using System.Reflection;
15 using System.Runtime.InteropServices;
17 namespace System.ComponentModel
21 public abstract class MemberDescriptor
25 private Attribute [] attrs;
26 private AttributeCollection attrCollection;
28 protected MemberDescriptor (string name, Attribute [] attrs)
34 protected MemberDescriptor (MemberDescriptor reference, Attribute [] attrs)
36 name = reference.name;
40 protected MemberDescriptor (string name)
45 protected MemberDescriptor (MemberDescriptor reference)
47 name = reference.name;
48 attrs = reference.AttributeArray;
51 protected virtual Attribute [] AttributeArray
57 ArrayList list = new ArrayList ();
58 FillAttributes (list);
60 ArrayList filtered = new ArrayList ();
61 foreach (Attribute at in list) {
63 for (int n=0; n<filtered.Count && !found; n++)
64 found = (filtered[n].GetType() == at.GetType ());
68 attrs = (Attribute[]) filtered.ToArray (typeof(Attribute));
80 protected virtual void FillAttributes(System.Collections.IList attributeList)
85 public virtual AttributeCollection Attributes
89 if (attrCollection == null)
90 attrCollection = CreateAttributeCollection ();
91 return attrCollection;
95 protected virtual AttributeCollection CreateAttributeCollection()
97 return new AttributeCollection (AttributeArray);
100 public virtual string Category
104 return ((CategoryAttribute) Attributes [typeof (CategoryAttribute)]).Category;
108 public virtual string Description
112 foreach (Attribute attr in AttributeArray)
114 if (attr is DescriptionAttribute)
115 return ((DescriptionAttribute) attr).Description;
121 public virtual bool DesignTimeOnly
125 foreach (Attribute attr in AttributeArray)
127 if (attr is DesignOnlyAttribute)
128 return ((DesignOnlyAttribute) attr).IsDesignOnly;
135 public virtual string DisplayName
143 public virtual string Name
151 public virtual bool IsBrowsable
155 foreach (Attribute attr in AttributeArray)
157 if (attr is BrowsableAttribute)
158 return ((BrowsableAttribute) attr).Browsable;
165 protected virtual int NameHashCode
169 return name.GetHashCode ();
173 public override int GetHashCode()
175 return base.GetHashCode ();
178 public override bool Equals(object obj)
180 MemberDescriptor other = obj as MemberDescriptor;
181 if (other == null) return false;
183 return other.name == name;
186 protected static ISite GetSite(object component)
188 if (component is Component)
189 return ((Component) component).Site;
195 protected static object GetInvokee(Type componentClass, object component)
197 // FIXME WHAT should that do???
199 // Lluis: Checked with VS.NET and it always return the component, even if
200 // it has its own designer set with DesignerAttribute. So, no idea
201 // what this should do.
205 protected static MethodInfo FindMethod(Type componentClass, string name,
206 Type[ ] args, Type returnType)
208 return FindMethod (componentClass, name, args, returnType, true);
211 protected static MethodInfo FindMethod(Type componentClass, string name,
212 Type[ ] args, Type returnType, bool publicOnly)
215 if (publicOnly == true)
216 bf = BindingFlags.Public;
218 bf = BindingFlags.NonPublic | BindingFlags.Public;
219 // FIXME returnType is not taken into account. AFAIK methods are not allowed to only
220 // differ by return type anyway
221 return componentClass.GetMethod (name, bf, null, CallingConventions.Any, args, null);