2 // System.ComponentModel.AttributeCollection.cs
5 // Rodrigo Moya (rodrigo@ximian.com)
6 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
8 // (C) 2002 Ximian, Inc. (http://www.ximian.com)
12 using System.Collections;
13 using System.Reflection;
15 namespace System.ComponentModel
17 public class AttributeCollection : ICollection, IEnumerable
19 private ArrayList attrList = new ArrayList ();
20 public static readonly AttributeCollection Empty = new AttributeCollection (null);
22 public AttributeCollection (Attribute[] attributes)
24 if (attributes != null)
25 for (int i = 0; i < attributes.Length; i++)
26 attrList.Add (attributes[i]);
29 public bool Contains (Attribute attr)
31 return attrList.Contains (attr);
34 public bool Contains (Attribute [] attributes)
36 if (attributes == null)
39 foreach (Attribute attr in attributes)
46 public void CopyTo (Array array, int index)
48 attrList.CopyTo (array, index);
51 public IEnumerator GetEnumerator ()
53 return attrList.GetEnumerator ();
56 public bool Matches (Attribute attr)
58 foreach (Attribute a in attrList)
64 public bool Matches (Attribute [] attributes)
66 foreach (Attribute a in attributes)
72 protected Attribute GetDefaultAttribute (Type attributeType)
75 BindingFlags bf = BindingFlags.Public | BindingFlags.Static;
77 FieldInfo def = attributeType.GetField ("Default", bf);
79 attr = Activator.CreateInstance (attributeType) as Attribute;
80 if (attr != null && !attr.IsDefaultAttribute ())
83 attr = (Attribute) def.GetValue (null);
89 public bool IsSynchronized {
91 return attrList.IsSynchronized;
95 public object SyncRoot {
97 return attrList.SyncRoot;
103 return attrList.Count;
107 public virtual Attribute this[Type type] {
109 Attribute attr = null;
110 foreach (Attribute a in attrList) {
111 if (a.GetType () == type){
118 attr = GetDefaultAttribute (type);
124 public virtual Attribute this[int index] {
126 return (Attribute) attrList [index];