AttributeCollection.Matches Método

Definición

Determina si un atributo o una matriz de atributos especificados coincide con un atributo o una matriz de atributos de la colección.

Sobrecargas

Matches(Attribute)

Determina si un atributo especificado es igual a un atributo de la colección.

Matches(Attribute[])

Determina si los atributos en la matriz especificada son iguales a los de la colección.

Matches(Attribute)

Determina si un atributo especificado es igual a un atributo de la colección.

public:
 bool Matches(Attribute ^ attribute);
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

Instancia de Attribute que se va a comparar con los atributos de esta colección.

Devoluciones

Boolean

true si el atributo forma parte de la colección y tiene el mismo valor que el atributo de la colección; en caso contrario, false.

Ejemplos

En el ejemplo de código siguiente se comprueba que BrowsableAttribute es un miembro de la colección y que se ha establecido trueen . Se supone que button1 y textBox1 se han creado en un formulario.

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

Comentarios

Un atributo puede proporcionar compatibilidad con la coincidencia.

La diferencia entre los Matches métodos y Contains es que Matches llama al Match método en un atributo y Contains llama al Equals método .

Para la mayoría de los atributos, estos métodos hacen lo mismo. Sin embargo, en el caso de los atributos que pueden tener varias marcas, Match normalmente se implementa para que devuelva true si se cumple alguna de las marcas. Por ejemplo, considere un atributo de enlace de datos con las marcas booleanas "SupportsSql", "SupportsOleDb" y "SupportsXml". Este atributo puede estar presente en una propiedad que admite los tres enfoques de enlace de datos. A menudo, será el caso de que un programador necesite saber solo si hay disponible un enfoque determinado, no los tres. Por lo tanto, un programador podría usar Match con una instancia del atributo que contiene solo las marcas que necesita el programador.

Consulte también

Se aplica a

Matches(Attribute[])

Determina si los atributos en la matriz especificada son iguales a los de la colección.

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

Parámetros

attributes
Attribute[]

Matriz de MemberAttributes que se va a comparar con los atributos de esta colección.

Devoluciones

Boolean

true si todos los atributos de la matriz forman parte de la colección y tienen los mismos valores que los atributos de la colección; en caso contrario, false.

Ejemplos

En el ejemplo de código siguiente se comparan los atributos de un botón y un cuadro de texto para ver si coinciden. Se supone que button1 y textBox1 se han creado en un formulario.

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

Comentarios

Un atributo puede proporcionar compatibilidad con la coincidencia.

Consulte también

Se aplica a