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.Reflection;
14 using System.Runtime.InteropServices;
16 namespace System.ComponentModel
20 public abstract class MemberDescriptor
24 private Attribute [] attrs;
25 private AttributeCollection attrCollection;
27 protected MemberDescriptor (string name, Attribute [] attrs)
33 protected MemberDescriptor (MemberDescriptor reference, Attribute [] attrs)
35 name = reference.name;
39 protected MemberDescriptor (string name)
44 protected MemberDescriptor (MemberDescriptor reference)
46 name = reference.name;
47 attrs = reference.AttributeArray;
50 protected virtual Attribute [] AttributeArray
56 ArrayList list = new ArrayList ();
57 FillAttributes (list);
59 ArrayList filtered = new ArrayList ();
60 foreach (Attribute at in list) {
62 for (int n=0; n<filtered.Count && !found; n++)
63 found = (filtered[n].GetType() == at.GetType ());
67 attrs = (Attribute[]) filtered.ToArray (typeof(Attribute));
79 protected virtual void FillAttributes(System.Collections.IList attributeList)
84 public virtual AttributeCollection Attributes
88 if (attrCollection == null)
89 attrCollection = CreateAttributeCollection ();
90 return attrCollection;
94 protected virtual AttributeCollection CreateAttributeCollection()
96 return new AttributeCollection (AttributeArray);
99 public virtual string Category
103 return ((CategoryAttribute) Attributes [typeof (CategoryAttribute)]).Category;
107 public virtual string Description
111 foreach (Attribute attr in AttributeArray)
113 if (attr is DescriptionAttribute)
114 return ((DescriptionAttribute) attr).Description;
120 public virtual bool DesignTimeOnly
124 foreach (Attribute attr in AttributeArray)
126 if (attr is DesignOnlyAttribute)
127 return ((DesignOnlyAttribute) attr).IsDesignOnly;
134 public virtual string DisplayName
142 public virtual string Name
150 public virtual bool IsBrowsable
154 foreach (Attribute attr in AttributeArray)
156 if (attr is BrowsableAttribute)
157 return ((BrowsableAttribute) attr).Browsable;
164 protected virtual int NameHashCode
168 return name.GetHashCode ();
172 public override int GetHashCode()
174 return name.GetHashCode ();
177 public override bool Equals(object obj)
179 MemberDescriptor other = obj as MemberDescriptor;
180 if (obj == null) return false;
182 return other.name == name;
185 protected static ISite GetSite(object component)
187 if (component is Component)
188 return ((Component) component).Site;
194 protected static object GetInvokee(Type componentClass, object component)
196 // FIXME WHAT should that do???
198 // Lluis: Checked with VS.NET and it always return the component, even if
199 // it has its own designer set with DesignerAttribute. So, no idea
200 // what this should do.
204 protected static MethodInfo FindMethod(Type componentClass, string name,
205 Type[ ] args, Type returnType)
207 return FindMethod (componentClass, name, args, returnType, true);
210 protected static MethodInfo FindMethod(Type componentClass, string name,
211 Type[ ] args, Type returnType, bool publicOnly)
214 if (publicOnly == true)
215 bf = BindingFlags.Public;
217 bf = BindingFlags.NonPublic | BindingFlags.Public;
218 // FIXME returnType is not taken into account. AFAIK methods are not allowed to only
219 // differ by return type anyway
220 return componentClass.GetMethod (name, bf, null, CallingConventions.Any, args, null);