Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

AttributeCollection::Matches Method (Attribute^)

 

Determines whether a specified attribute is the same as an attribute in the collection.

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

public:
bool Matches(
	Attribute^ attribute
)

Parameters

attribute
Type: System::Attribute^

An instance of Attribute to compare with the attributes in this collection.

Return Value

Type: System::Boolean

true if the attribute is contained within the collection and has the same value as the attribute in the collection; otherwise, false.

An attribute can provide support for matching.

The difference between the Matches and Contains methods is that Matches calls the Match method on an attribute, and Contains calls the Equals method.

For most attributes, these methods do the same thing. For attributes that may have multiple flags, however, Match 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 Match with an instance of the attribute containing only the flags the programmer needs.

The following code example verifies that the BrowsableAttribute is a member of the collection and that it has been set to true. It assumes that button1 and textBox1 have been created on a form.

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

      // Checks to see if the browsable attribute is true.
      if ( attributes->Matches( BrowsableAttribute::Yes ) )
      {
         textBox1->Text = "button1 is browsable.";
      }
      else
      {
         textBox1->Text = "button1 is not browsable.";
      }
   }

.NET Framework
Available since 1.1
Return to top
Show:
© 2017 Microsoft