AttributeCollection.Matches Método

Definição

Determina se um atributo especificado ou uma matriz de atributos é igual a um atributo ou uma matriz de atributos na coleção.Determines whether a specified attribute or array of attributes is the same as an attribute or array of attributes in the collection.

Sobrecargas

Matches(Attribute)

Determina se um atributo especificado é o mesmo que um atributo na coleção.Determines whether a specified attribute is the same as an attribute in the collection.

Matches(Attribute[])

Determina se os atributos na matriz especificada são os mesmos que os atributos na coleção.Determines whether the attributes in the specified array are the same as the attributes in the collection.

Matches(Attribute)

Determina se um atributo especificado é o mesmo que um atributo na coleção.Determines whether a specified attribute is the same as an attribute in the collection.

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

Parâmetros

attribute
Attribute

Uma instância de Attribute para comparar aos atributos nesta coleção.An instance of Attribute to compare with the attributes in this collection.

Retornos

Boolean

true se o atributo estiver contido na coleção e tiver o mesmo valor que o atributo na coleção; caso contrário, false.true if the attribute is contained within the collection and has the same value as the attribute in the collection; otherwise, false.

Exemplos

O exemplo de código a seguir verifica se o BrowsableAttribute é um membro da coleção e se foi definido como true .The following code example verifies that the BrowsableAttribute is a member of the collection and that it has been set to true. Ele pressupõe que button1 e textBox1 tenham sido criados em um formulário.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.";
      }
   }
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

Comentários

Um atributo pode fornecer suporte para correspondência.An attribute can provide support for matching.

A diferença entre os Matches Contains métodos e é que Matches o chama o Match método em um atributo e Contains chama o Equals método.The difference between the Matches and Contains methods is that Matches calls the Match method on an attribute, and Contains calls the Equals method.

Para a maioria dos atributos, esses métodos fazem a mesma coisa.For most attributes, these methods do the same thing. No entanto, para atributos que podem ter vários sinalizadores, Match é normalmente implementado para que ele retorne true se algum dos sinalizadores for atendido.For attributes that may have multiple flags, however, Match is typically implemented so that it returns true if any of the flags are satisfied. Por exemplo, considere um atributo de vinculação de dados com os sinalizadores boolianos "SupportsSql", "SupportsOleDb" e "SupportsXml".For example, consider a data binding attribute with the Boolean flags "SupportsSql", "SupportsOleDb", and "SupportsXml". Esse atributo pode estar presente em uma propriedade que dá suporte a todas as três abordagens de vinculação de dados.This attribute may be present on a property that supports all three data binding approaches. Em geral, será o caso de um programador precisar saber apenas se uma determinada abordagem estiver disponível, e não todas três.It will often be the case that a programmer needs to know only if a particular approach is available, not all three. Portanto, um programador pode usar Match com uma instância do atributo que contém apenas os sinalizadores de que o programador precisa.Therefore, a programmer could use Match with an instance of the attribute containing only the flags the programmer needs.

Confira também

Aplica-se a

Matches(Attribute[])

Determina se os atributos na matriz especificada são os mesmos que os atributos na coleção.Determines whether the attributes in the specified array are the same as the attributes in the collection.

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

Parâmetros

attributes
Attribute[]

Uma matriz de MemberAttributes para comparar aos atributos nesta coleção.An array of MemberAttributes to compare with the attributes in this collection.

Retornos

Boolean

true se todos os atributos na matriz estiverem contidos na coleção e tiverem os mesmos valores como os atributos na coleção; caso contrário, false.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.

Exemplos

O exemplo de código a seguir compara os atributos em um botão e uma caixa de texto para ver se eles correspondem.The following code example compares the attributes in a button and a text box to see whether they match. Ele pressupõe que button1 e textBox1 tenham sido criados em um formulário.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.
      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

Comentários

Um atributo pode fornecer suporte para correspondência.An attribute can provide support for matching.

Confira também

Aplica-se a