AttributeCollection.Matches Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Determina se un attributo o una matrice di attributi specificata corrisponde a un attributo o a una matrice di attributi nella raccolta.
Overload
| Nome | Descrizione |
|---|---|
| Matches(Attribute) |
Determina se un attributo specificato è uguale a un attributo nella raccolta. |
| Matches(Attribute[]) |
Determina se gli attributi nella matrice specificata sono uguali agli attributi nella raccolta. |
Matches(Attribute)
Determina se un attributo specificato è uguale a un attributo nella raccolta.
public:
bool Matches(Attribute ^ attribute);
public bool Matches(Attribute attribute);
member this.Matches : Attribute -> bool
Public Function Matches (attribute As Attribute) As Boolean
Parametri
Valori restituiti
true se l'attributo è contenuto all'interno della raccolta e ha lo stesso valore dell'attributo nella raccolta; in caso contrario, false.
Esempio
Nell'esempio di codice seguente viene verificato che BrowsableAttribute è un membro della raccolta e che sia stato impostato su true. Si presuppone che button1 e textBox1 siano stati creati in un modulo.
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
Commenti
Un attributo può fornire supporto per la corrispondenza.
La differenza tra i Matches metodi e Contains è che Matches chiama il Match metodo su un attributo e Contains chiama il Equals metodo .
Per la maggior parte degli attributi, questi metodi eseguono la stessa operazione. Per gli attributi che possono avere più flag, tuttavia, Match viene in genere implementato in modo che restituisca true se uno dei flag è soddisfatto. Si consideri ad esempio un attributo di data binding con i flag booleani "SupportsSql", "SupportsOleDb" e "SupportsXml". Questo attributo può essere presente in una proprietà che supporta tutti e tre gli approcci di data binding. Spesso sarà il caso che un programmatore debba sapere solo se è disponibile un particolare approccio, non tutti e tre. Pertanto, un programmatore può usare Match con un'istanza dell'attributo contenente solo i flag necessari per il programmatore.
Vedi anche
Si applica a
Matches(Attribute[])
Determina se gli attributi nella matrice specificata sono uguali agli attributi nella raccolta.
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
Parametri
- attributes
- Attribute[]
Matrice di MemberAttributes da confrontare con gli attributi in questa raccolta.
Valori restituiti
true se tutti gli attributi nella matrice sono contenuti nella raccolta e hanno gli stessi valori degli attributi nella raccolta; in caso contrario, false.
Esempio
Nell'esempio di codice seguente vengono confrontati gli attributi di un pulsante e una casella di testo per verificare se corrispondono. Si presuppone che button1 e textBox1 siano stati creati in un modulo.
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
Commenti
Un attributo può fornire supporto per la corrispondenza.