Commit
[mono.git] / mcs / class / System / System.ComponentModel / AttributeCollection.cs
index 2c5c6d840e0f66f8eba4915e9ab4ae9992b9570b..8e11797c9eb8d8d8810b006d6851727ecb7574bb 100644 (file)
@@ -37,7 +37,7 @@ using System.Runtime.InteropServices;
 namespace System.ComponentModel
 {
        [ComVisible (true)]
-       public class AttributeCollection : ICollection, IEnumerable
+       public class AttributeCollection : ICollection
        {
                private ArrayList attrList = new ArrayList ();
                public static readonly AttributeCollection Empty = new AttributeCollection ((ArrayList)null);
@@ -47,16 +47,37 @@ namespace System.ComponentModel
                        attrList = attributes;
                }
                
+#if NET_2_0
+               public AttributeCollection (params Attribute[] attributes)
+#else
                public AttributeCollection (Attribute[] attributes)
+#endif
                {
                        if (attributes != null)
                                for (int i = 0; i < attributes.Length; i++)
                                        attrList.Add (attributes[i]);
                }
 
+#if NET_2_0
+               public static AttributeCollection FromExisting (AttributeCollection existing, params Attribute [] newAttributes)
+               {
+                       if (existing == null)
+                               throw new ArgumentNullException ("existing");
+                       AttributeCollection ret = new AttributeCollection ();
+                       ret.attrList.AddRange (existing.attrList);
+                       if (newAttributes != null)
+                               ret.attrList.AddRange (newAttributes);
+                       return ret;
+               }
+#endif
+
                public bool Contains (Attribute attr)
                {
-                       return attrList.Contains (attr);
+                       Attribute at = this [attr.GetType ()];
+                       if (at != null)
+                               return attr.Equals (at);
+                       else
+                               return false;
                }
 
                public bool Contains (Attribute [] attributes)
@@ -76,6 +97,10 @@ namespace System.ComponentModel
                        attrList.CopyTo (array, index);
                }
 
+               IEnumerator IEnumerable.GetEnumerator () {
+                       return GetEnumerator ();
+               }
+
                public IEnumerator GetEnumerator ()
                {
                        return attrList.GetEnumerator ();
@@ -128,6 +153,12 @@ namespace System.ComponentModel
                        }
                }
                
+               int ICollection.Count {
+                       get {
+                               return Count;
+                       }
+               }
+
                public int Count {
                        get {
                                return attrList.Count;
@@ -138,7 +169,7 @@ namespace System.ComponentModel
                        get {
                                Attribute attr = null;
                                foreach (Attribute a in attrList) {
-                                       if (a.GetType () == type){
+                                       if (type.IsAssignableFrom (a.GetType ())) {
                                                attr = a;
                                                break;
                                        }