AttributeCollection.Matches Methode

Definition

Bestimmt, ob ein angegebenes Attribut oder array von Attributen mit einem Attribut oder Array von Attributen in der Auflistung identisch ist.

Überlädt

Name Beschreibung
Matches(Attribute)

Bestimmt, ob ein angegebenes Attribut mit einem Attribut in der Auflistung identisch ist.

Matches(Attribute[])

Bestimmt, ob die Attribute im angegebenen Array mit den Attributen in der Auflistung identisch sind.

Matches(Attribute)

Bestimmt, ob ein angegebenes Attribut mit einem Attribut in der Auflistung identisch ist.

public:
 bool Matches(Attribute ^ attribute);
public bool Matches(Attribute attribute);
member this.Matches : Attribute -> bool
Public Function Matches (attribute As Attribute) As Boolean

Parameter

attribute
Attribute

Eine Instanz des Vergleichs Attribute mit den Attributen in dieser Auflistung.

Gibt zurück

truewenn das Attribut in der Auflistung enthalten ist und denselben Wert wie das Attribut in der Auflistung aufweist; andernfalls . false

Beispiele

Im folgenden Codebeispiel wird überprüft, ob es BrowsableAttribute sich um ein Element der Auflistung handelt und dass es auf true. festgelegt wurde. Es wird davon ausgegangen, dass button1 und textBox1 auf einem Formular erstellt wurden.

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.";
      }
   }
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.";
 }
Private Sub MatchesAttribute
    ' Creates a new collection and assigns it the attributes for button
    Dim attributes As AttributeCollection
    attributes = TypeDescriptor.GetAttributes(button1)

    ' Checks to see if the browsable attribute is true.
    If attributes.Matches(BrowsableAttribute.Yes) Then
        textBox1.Text = "button1 is browsable."
    Else
        textBox1.Text = "button1 is not browsable."
    End If
End Sub

Hinweise

Ein Attribut kann Unterstützung für den Abgleich bieten.

Der Unterschied zwischen den Methoden und Contains den Matches Methoden besteht darin, dass Matches die Match Methode für ein Attribut aufgerufen und Contains die Equals Methode aufgerufen wird.

Bei den meisten Attributen führen diese Methoden dasselbe aus. Bei Attributen, die möglicherweise mehrere Flags aufweisen, wird jedoch in der Regel implementiert, sodass sie zurückgegeben true wird, Match wenn eines der Flags erfüllt ist. Betrachten Sie z. B. ein Datenbindungsattribut mit den booleschen Flags "SupportsSql", "SupportsOleDb" und "SupportsXml". Dieses Attribut kann für eine Eigenschaft vorhanden sein, die alle drei Datenbindungsansätze unterstützt. Es wird oft der Fall sein, dass ein Programmierer nur wissen muss, wenn ein bestimmter Ansatz verfügbar ist, nicht alle drei. Daher könnte ein Programmierer mit einer Instanz des Attributs verwenden Match , das nur die Flags enthält, die der Programmierer benötigt.

Weitere Informationen

Gilt für:

Matches(Attribute[])

Bestimmt, ob die Attribute im angegebenen Array mit den Attributen in der Auflistung identisch sind.

public:
 bool Matches(cli::array <Attribute ^> ^ attributes);
public bool Matches(Attribute[] attributes);
member this.Matches : Attribute[] -> bool
Public Function Matches (attributes As Attribute()) As Boolean

Parameter

attributes
Attribute[]

Ein Array, das MemberAttributes mit den Attributen in dieser Auflistung verglichen werden soll.

Gibt zurück

truewenn alle Attribute im Array in der Auflistung enthalten sind und dieselben Werte wie die Attribute in der Auflistung aufweisen; andernfalls . false

Beispiele

Im folgenden Codebeispiel werden die Attribute in einer Schaltfläche und ein Textfeld verglichen, um festzustellen, ob sie übereinstimmen. Es wird davon ausgegangen, dass button1 und textBox1 auf einem Formular erstellt wurden.

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.
      array<Attribute^>^ myAttrArray = gcnew array<Attribute^>(100);
      TypeDescriptor::GetAttributes( textBox1 )->CopyTo( myAttrArray, 0 );
      if ( myCollection->Matches( myAttrArray ) )
      {
         textBox1->Text = "The attributes in the button and text box match.";
      }
      else
      {
         textBox1->Text = "The attributes in the button and text box do not match.";
      }
   }
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.";
   else
      textBox1.Text = "The attributes in the button and text box do not match.";
}
Private Sub MatchesAttributes()
    ' Creates a new collection and assigns it the attributes for button1.
    Dim myCollection As AttributeCollection
    myCollection = TypeDescriptor.GetAttributes(button1)
       
    ' Checks to see whether the attributes in myCollection match the attributes.
    ' for textBox1.
    Dim myAttrArray(100) As Attribute
    TypeDescriptor.GetAttributes(textBox1).CopyTo(myAttrArray, 0)
    If myCollection.Matches(myAttrArray) Then
        textBox1.Text = "The attributes in the button and text box match."
    Else
        textBox1.Text = "The attributes in the button and text box do not match."
    End If
End Sub

Hinweise

Ein Attribut kann Unterstützung für den Abgleich bieten.

Weitere Informationen

Gilt für: