AttributeCollection.Matches Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Determina se um atributo ou array especificado de atributos é igual a um atributo ou array de atributos na coleção.
Sobrecargas
| Name | Description |
|---|---|
| Matches(Attribute) |
Determina se um atributo especificado é igual a um atributo na coleção. |
| Matches(Attribute[]) |
Determina se os atributos no array especificado são os mesmos que os atributos da coleção. |
Matches(Attribute)
Determina se um atributo especificado é igual a 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
Devoluções
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 seguinte exemplo de código verifica se o BrowsableAttribute é um membro da coleção e que foi definido como true. Assume que button1 e textBox1 foram criados numa forma.
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
Observações
Um atributo pode fornecer suporte para o emparelhamento.
A diferença entre os Matches métodos e Contains é que Matches chama o Match método num atributo, e Contains chama o Equals método.
Para a maioria dos atributos, estes métodos fazem o mesmo. Para atributos que podem ter múltiplas flags, no entanto, Match é normalmente implementado de modo a que retorne true se alguma das flags for satisfeita. Por exemplo, considere um atributo de ligação de dados com as flags booleanas "SupportsSql", "SupportsOleDb" e "SupportsXml". Este atributo pode estar presente numa propriedade que suporta as três abordagens de ligação de dados. Muitas vezes, um programador só precisa de saber se existe uma abordagem específica, não as três. Portanto, um programador pode usar Match com uma instância do atributo contendo apenas as flags de que o programador necessita.
Ver também
Aplica-se a
Matches(Attribute[])
Determina se os atributos no array especificado são os mesmos que os atributos da 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[]
Um conjunto de MemberAttributes para comparar com os atributos desta coleção.
Devoluções
true se todos os atributos do array estiverem contidos na coleção e tiverem os mesmos valores que os atributos da coleção; caso contrário, false.
Exemplos
O exemplo de código seguinte compara os atributos num botão e numa caixa de texto para ver se correspondem. Assume que button1 e textBox1 foram criados numa forma.
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
Observações
Um atributo pode fornecer suporte para o emparelhamento.