using System;
using System.Collections;
using System.Reflection;
using System.Runtime.InteropServices;
namespace System.ComponentModel
{
/// Represents a collection of attributes.
// Token: 0x02000057 RID: 87
[ComVisible(true)]
public class AttributeCollection : ICollection, IEnumerable
{
// Token: 0x06000353 RID: 851 RVA: 0x0000A440 File Offset: 0x00008640
internal AttributeCollection(ArrayList attributes)
{
if (attributes != null)
{
this.attrList = attributes;
}
}
/// Initializes a new instance of the class.
/// An array of type that provides the attributes for this collection.
///
/// is null.
// Token: 0x06000354 RID: 852 RVA: 0x0000A460 File Offset: 0x00008660
public AttributeCollection(params Attribute[] attributes)
{
if (attributes != null)
{
for (int i = 0; i < attributes.Length; i++)
{
this.attrList.Add(attributes[i]);
}
}
}
/// Returns an for the .
/// An for the .
// Token: 0x06000356 RID: 854 RVA: 0x0000A4B8 File Offset: 0x000086B8
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
/// Gets a value indicating whether access to the collection is synchronized (thread-safe).
/// true if access to the collection is synchronized (thread-safe); otherwise, false.
// Token: 0x170000E9 RID: 233
// (get) Token: 0x06000357 RID: 855 RVA: 0x0000A4C0 File Offset: 0x000086C0
bool ICollection.IsSynchronized
{
get
{
return this.attrList.IsSynchronized;
}
}
/// Gets an object that can be used to synchronize access to the collection.
/// An object that can be used to synchronize access to the collection.
// Token: 0x170000EA RID: 234
// (get) Token: 0x06000358 RID: 856 RVA: 0x0000A4D0 File Offset: 0x000086D0
object ICollection.SyncRoot
{
get
{
return this.attrList.SyncRoot;
}
}
/// Gets the number of elements contained in the collection.
/// The number of elements contained in the collection.
// Token: 0x170000EB RID: 235
// (get) Token: 0x06000359 RID: 857 RVA: 0x0000A4E0 File Offset: 0x000086E0
int ICollection.Count
{
get
{
return this.Count;
}
}
/// Creates a new from an existing .
/// A new that is a copy of .
/// An from which to create the copy.
/// An array of type that provides the attributes for this collection. Can be null.
///
/// is null.
// Token: 0x0600035A RID: 858 RVA: 0x0000A4E8 File Offset: 0x000086E8
public static AttributeCollection FromExisting(AttributeCollection existing, params Attribute[] newAttributes)
{
if (existing == null)
{
throw new ArgumentNullException("existing");
}
AttributeCollection attributeCollection = new AttributeCollection(new Attribute[0]);
attributeCollection.attrList.AddRange(existing.attrList);
if (newAttributes != null)
{
attributeCollection.attrList.AddRange(newAttributes);
}
return attributeCollection;
}
/// Determines whether this collection of attributes has the specified attribute.
/// true if the collection contains the attribute or is the default attribute for the type of attribute; otherwise, false.
/// An to find in the collection.
// Token: 0x0600035B RID: 859 RVA: 0x0000A538 File Offset: 0x00008738
public bool Contains(Attribute attr)
{
Attribute attribute = this[attr.GetType()];
return attribute != null && attr.Equals(attribute);
}
/// Determines whether this attribute collection contains all the specified attributes in the attribute array.
/// true if the collection contains all the attributes; otherwise, false.
/// An array of type to find in the collection.
// Token: 0x0600035C RID: 860 RVA: 0x0000A564 File Offset: 0x00008764
public bool Contains(Attribute[] attributes)
{
if (attributes == null)
{
return true;
}
foreach (Attribute attribute in attributes)
{
if (!this.Contains(attribute))
{
return false;
}
}
return true;
}
/// Copies the collection to an array, starting at the specified index.
/// The to copy the collection to.
/// The index to start from.
// Token: 0x0600035D RID: 861 RVA: 0x0000A5A4 File Offset: 0x000087A4
public void CopyTo(Array array, int index)
{
this.attrList.CopyTo(array, index);
}
/// Gets an enumerator for this collection.
/// An enumerator of type .
// Token: 0x0600035E RID: 862 RVA: 0x0000A5B4 File Offset: 0x000087B4
public IEnumerator GetEnumerator()
{
return this.attrList.GetEnumerator();
}
/// Determines whether a specified attribute is the same as an attribute in the collection.
/// true if the attribute is contained within the collection and has the same value as the attribute in the collection; otherwise, false.
/// An instance of to compare with the attributes in this collection.
// Token: 0x0600035F RID: 863 RVA: 0x0000A5C4 File Offset: 0x000087C4
public bool Matches(Attribute attr)
{
foreach (object obj in this.attrList)
{
Attribute attribute = (Attribute)obj;
if (attribute.Match(attr))
{
return true;
}
}
return false;
}
/// Determines whether the attributes in the specified array are the same as the attributes in the collection.
/// true if all the attributes in the array are contained in the collection and have the same values as the attributes in the collection; otherwise, false.
/// An array of to compare with the attributes in this collection.
// Token: 0x06000360 RID: 864 RVA: 0x0000A644 File Offset: 0x00008844
public bool Matches(Attribute[] attributes)
{
foreach (Attribute attribute in attributes)
{
if (!this.Matches(attribute))
{
return false;
}
}
return true;
}
/// Returns the default of a given .
/// An .
/// The of the attribute to retrieve.
// Token: 0x06000361 RID: 865 RVA: 0x0000A67C File Offset: 0x0000887C
protected Attribute GetDefaultAttribute(Type attributeType)
{
Attribute attribute = null;
BindingFlags bindingFlags = BindingFlags.Static | BindingFlags.Public;
FieldInfo field = attributeType.GetField("Default", bindingFlags);
if (field == null)
{
ConstructorInfo constructor = attributeType.GetConstructor(Type.EmptyTypes);
if (constructor != null)
{
attribute = constructor.Invoke(null) as Attribute;
}
if (attribute != null && !attribute.IsDefaultAttribute())
{
attribute = null;
}
}
else
{
attribute = (Attribute)field.GetValue(null);
}
return attribute;
}
/// Gets the number of attributes.
/// The number of attributes.
// Token: 0x170000EC RID: 236
// (get) Token: 0x06000362 RID: 866 RVA: 0x0000A6E8 File Offset: 0x000088E8
public int Count
{
get
{
return (this.attrList == null) ? 0 : this.attrList.Count;
}
}
/// Gets the attribute with the specified type.
/// The with the specified type or, if the attribute does not exist, the default value for the attribute type.
/// The of the to get from the collection.
// Token: 0x170000ED RID: 237
public virtual Attribute this[Type type]
{
get
{
Attribute attribute = null;
if (this.attrList != null)
{
foreach (object obj in this.attrList)
{
Attribute attribute2 = (Attribute)obj;
if (type.IsAssignableFrom(attribute2.GetType()))
{
attribute = attribute2;
break;
}
}
}
if (attribute == null)
{
attribute = this.GetDefaultAttribute(type);
}
return attribute;
}
}
/// Gets the attribute with the specified index number.
/// The with the specified index number.
/// The zero-based index of .
// Token: 0x170000EE RID: 238
public virtual Attribute this[int index]
{
get
{
return (Attribute)this.attrList[index];
}
}
// Token: 0x04000118 RID: 280
private ArrayList attrList = new ArrayList();
/// Specifies an empty collection that you can use, rather than creating a new one. This field is read-only.
// Token: 0x04000119 RID: 281
public static readonly AttributeCollection Empty = new AttributeCollection(null);
}
}