AttributeCollection.Matches Método
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Determina se um atributo ou matriz de atributos especificado é o mesmo que um atributo ou uma matriz de atributos na coleção.
Sobrecargas
| Nome | Description |
|---|---|
| Matches(Attribute) |
Determina se um atributo especificado é o mesmo que um atributo na coleção. |
| Matches(Attribute[]) |
Determina se os atributos na matriz especificada são os mesmos que os atributos na coleção. |
Matches(Attribute)
Determina se um atributo especificado é o mesmo que um atributo na coleção.
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
Retornos
true se o atributo estiver contido na coleção e tiver o mesmo valor que o atributo na coleção; caso contrário, false.
Exemplos
O exemplo de código a seguir verifica se ele BrowsableAttribute é um membro da coleção e se ele foi definido como true. Ele pressupõe isso button1 e textBox1 foi criado em um formulário.
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.
A diferença entre os métodos e Contains os Matches métodos é que Matches chama o Match método em um atributo e Contains chama o Equals método.
Para a maioria dos atributos, esses métodos fazem a mesma coisa. Para atributos que podem ter vários sinalizadores, no entanto, Match normalmente é implementado para que ele retorne true se qualquer um dos sinalizadores estiver satisfeito. Por exemplo, considere um atributo de associação de dados com os sinalizadores boolianos "SupportsSql", "SupportsOleDb" e "SupportsXml". Esse atributo pode estar presente em uma propriedade que dá suporte a todas as três abordagens de associação de dados. Muitas vezes, será o caso de um programador precisar saber apenas se uma abordagem específica está disponível, não todas as três. Portanto, um programador pode usar Match com uma instância do atributo que contém apenas os sinalizadores de que o programador precisa.
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.
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 comparação com os atributos nesta coleção.
Retornos
true se todos os atributos na matriz estiverem contidos na coleção e tiverem os mesmos valores que os atributos na coleção; caso contrário, 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. Ele pressupõe isso button1 e textBox1 foi criado em um formulário.
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.