System.ComponentModel.AttributeCollection.Contains Method

Determines whether this collection of attributes has the specified attribute.

Syntax

public bool Contains (Attribute attr)

Parameters

attr
Documentation for this section has not yet been entered.

Returns

true if the collection contains the attribute or is the default attribute for the type of attribute; otherwise, false.

Remarks

This collection has the specified attribute if the specified type of attribute exists in the collection, and if the value of the specified attribute is the same as the value of the instance of the attribute in the collection.

The difference between the AttributeCollection.Matches(Attribute) and AttributeCollection.Contains(Attribute) methods is that AttributeCollection.Matches(Attribute) calls the Attribute.Match(object) method on an attribute, and AttributeCollection.Contains(Attribute) calls the object.Equals(object) method.

For most attributes, these methods do the same thing. For attributes that may have multiple flags, however, Attribute.Match(object) is typically implemented so that it returns true if any of the flags are satisfied. For example, consider a data binding attribute with the Boolean flags "SupportsSql", "SupportsOleDb", and "SupportsXml". This attribute may be present on a property that supports all three data-binding approaches. It will often be the case that a programmer needs to know only if a particular approach is available, not all three. Therefore, a programmer could use Attribute.Match(object) with an instance of the attribute containing only the flags the programmer needs.

Requirements

Namespace: System.ComponentModel
Assembly: System (in System.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0