2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / System / System.ComponentModel / MemberDescriptor.cs
index f0a3c589a22fd3179acf0dde594d99901a87d8eb..5327f3444c60e79093fb57141f4f604558e7ea24 100755 (executable)
@@ -9,7 +9,29 @@
 // (C) 2003 Andreas Nahr
 //
 
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
 using System;
+using System.Collections;
 using System.Reflection;
 using System.Runtime.InteropServices;
 
@@ -21,41 +43,52 @@ namespace System.ComponentModel
     {
 
         private string name;
-        private string displayName;
         private Attribute [] attrs;
         private AttributeCollection attrCollection;
                
         protected MemberDescriptor (string name, Attribute [] attrs)
         {
             this.name = name;
-            this.displayName = name;
             this.attrs = attrs;
         }
 
         protected MemberDescriptor (MemberDescriptor reference, Attribute [] attrs)
         {
             name = reference.name;
-            this.displayName = name;
             this.attrs = attrs;
         }
 
         protected MemberDescriptor (string name)
         {
             this.name = name;
-            this.displayName = name;
         }
 
         protected MemberDescriptor (MemberDescriptor reference)
         {
             name = reference.name;
-            this.displayName = name;
-            attrs = reference.attrs;
+            attrs = reference.AttributeArray;
         }
 
         protected virtual Attribute [] AttributeArray 
         {
             get 
             {
+                               if (attrs == null) 
+                               {
+                                       ArrayList list = new ArrayList ();
+                                       FillAttributes (list);
+                                       
+                                       ArrayList filtered = new ArrayList ();
+                                       foreach (Attribute at in list) {
+                                               bool found = false;
+                                               for (int n=0; n<filtered.Count && !found; n++)
+                                                       found = (filtered[n].GetType() == at.GetType ());
+                                               if (!found)
+                                                       filtered.Add (at);
+                                       }
+                                       attrs = (Attribute[]) filtered.ToArray (typeof(Attribute));
+                               }
+                               
                 return attrs;
             }
 
@@ -65,13 +98,9 @@ namespace System.ComponentModel
             }
         }
 
-        [MonoTODO]
         protected virtual void FillAttributes(System.Collections.IList attributeList)
         {
-            // LAMESPEC/FIXME - I don't think this is correct, but didn't really understand
-            // what this sub is good for
-            attributeList = this.attrs;
-            return;
+                       // to be overriden
         }
 
         public virtual AttributeCollection Attributes
@@ -86,7 +115,7 @@ namespace System.ComponentModel
 
         protected virtual AttributeCollection CreateAttributeCollection()
         {
-            return new AttributeCollection (attrs);
+            return new AttributeCollection (AttributeArray);
         }
                        
         public virtual string Category 
@@ -101,7 +130,7 @@ namespace System.ComponentModel
         {
             get 
             {
-                foreach (Attribute attr in attrs)
+                foreach (Attribute attr in AttributeArray)
                 {
                     if (attr is DescriptionAttribute)
                         return ((DescriptionAttribute) attr).Description;
@@ -114,7 +143,7 @@ namespace System.ComponentModel
         {
             get 
             {
-                foreach (Attribute attr in attrs)
+                foreach (Attribute attr in AttributeArray)
                 {
                     if (attr is DesignOnlyAttribute)
                         return ((DesignOnlyAttribute) attr).IsDesignOnly;
@@ -128,7 +157,7 @@ namespace System.ComponentModel
         {
             get 
             {
-                return displayName;
+                return name;
             }
         }
 
@@ -144,7 +173,7 @@ namespace System.ComponentModel
         {
             get 
             {
-                foreach (Attribute attr in attrs)
+                foreach (Attribute attr in AttributeArray)
                 {
                     if (attr is BrowsableAttribute)
                         return ((BrowsableAttribute) attr).Browsable;
@@ -164,20 +193,15 @@ namespace System.ComponentModel
 
         public override int GetHashCode() 
         {
-            return name.GetHashCode ();
+            return base.GetHashCode ();
         }
 
-        [MonoTODO ("Probably not correctly implemented (too harsh?)")]
         public override bool Equals(object obj)
         {
-            if (!(obj is MemberDescriptor))
-                return false;
-            if (obj == this)
-                return true;
-            return (((MemberDescriptor) obj).AttributeArray == attrs) &&
-                (((MemberDescriptor) obj).Attributes == attrCollection) &&
-                (((MemberDescriptor) obj).DisplayName == displayName) &&
-                (((MemberDescriptor) obj).Name == name);
+                       MemberDescriptor other = obj as MemberDescriptor;
+            if (other == null) return false;
+                       
+            return other.name == name;
         }
 
         protected static ISite GetSite(object component)
@@ -192,7 +216,11 @@ namespace System.ComponentModel
         protected static object GetInvokee(Type componentClass, object component)
         {
             // FIXME WHAT should that do???
-            throw new NotImplementedException ();
+                       
+                       // Lluis: Checked with VS.NET and it always return the component, even if
+                       // it has its own designer set with DesignerAttribute. So, no idea
+                       // what this should do.
+            return component;
         }
 
         protected static MethodInfo FindMethod(Type componentClass, string name,