AttributeCollection.Matches Method (Attribute[])


Determines whether the attributes in the specified array are the same as the attributes in the collection.

Namespace:   System.ComponentModel
Assembly:  System (in System.dll)

public bool Matches(
	Attribute[] attributes


Type: System.Attribute[]

An array of MemberAttributes to compare with the attributes in this collection.

Return Value

Type: System.Boolean

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 attribute can provide support for matching.

The following code example compares the attributes in a button and a text box to see whether they match. It assumes that button1 and textBox1 have been created on a form.

private void MatchesAttributes() {
   // Creates a new collection and assigns it the attributes for button1.
   AttributeCollection myCollection;
   myCollection = TypeDescriptor.GetAttributes(button1);

   // Checks to see whether the attributes in myCollection match the attributes for textBox1.
   Attribute[] myAttrArray = new Attribute[100];
   TypeDescriptor.GetAttributes(textBox1).CopyTo(myAttrArray, 0);
   if (myCollection.Matches(myAttrArray))
      textBox1.Text = "The attributes in the button and text box match.";
      textBox1.Text = "The attributes in the button and text box do not match.";

.NET Framework
Available since 1.1
Return to top