AttributeCollection.Matches Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Bepaalt of een opgegeven kenmerk of matrix van kenmerken hetzelfde is als een kenmerk of matrix met kenmerken in de verzameling.
Overloads
| Name | Description |
|---|---|
| Matches(Attribute) |
Bepaalt of een opgegeven kenmerk hetzelfde is als een kenmerk in de verzameling. |
| Matches(Attribute[]) |
Bepaalt of de kenmerken in de opgegeven matrix hetzelfde zijn als de kenmerken in de verzameling. |
Matches(Attribute)
Bepaalt of een opgegeven kenmerk hetzelfde is als een kenmerk in de verzameling.
public:
bool Matches(Attribute ^ attribute);
public bool Matches(Attribute attribute);
member this.Matches : Attribute -> bool
Public Function Matches (attribute As Attribute) As Boolean
Parameters
- attribute
- Attribute
Een exemplaar van Attribute het vergelijken met de kenmerken in deze verzameling.
Retouren
true als het kenmerk zich in de verzameling bevindt en dezelfde waarde heeft als het kenmerk in de verzameling; anders, false.
Voorbeelden
In het volgende codevoorbeeld wordt gecontroleerd of het BrowsableAttribute lid is van de verzameling en of deze is ingesteld op true. Hierbij wordt ervan uitgegaan dat button1 en textBox1 zijn gemaakt op een formulier.
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
Opmerkingen
Een kenmerk kan ondersteuning bieden voor overeenkomende functies.
Het verschil tussen de Matches en Contains methoden is dat Matches de Match methode wordt aangeroepen op een kenmerk en Contains de Equals methode wordt aangeroepen.
Voor de meeste kenmerken doen deze methoden hetzelfde. Voor kenmerken die mogelijk meerdere vlaggen hebben, Match wordt echter meestal geïmplementeerd, zodat deze wordt geretourneerd true als aan een van de vlaggen wordt voldaan. Denk bijvoorbeeld aan een kenmerk voor gegevensbinding met de Booleaanse vlaggen 'SupportsSql', 'SupportsOleDb' en 'SupportsXml'. Dit kenmerk kan aanwezig zijn op een eigenschap die ondersteuning biedt voor alle drie de methoden voor gegevensbinding. Het komt vaak voor dat een programmeur alleen moet weten als een bepaalde benadering beschikbaar is, niet alle drie. Daarom kan een programmeur gebruikmaken Match van een exemplaar van het kenmerk dat alleen de vlaggen bevat die de programmeur nodig heeft.
Zie ook
Van toepassing op
Matches(Attribute[])
Bepaalt of de kenmerken in de opgegeven matrix hetzelfde zijn als de kenmerken in de verzameling.
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
Parameters
- attributes
- Attribute[]
Een matrix die MemberAttributes moet worden vergeleken met de kenmerken in deze verzameling.
Retouren
true als alle kenmerken in de matrix zijn opgenomen in de verzameling en dezelfde waarden hebben als de kenmerken in de verzameling; anders, false.
Voorbeelden
In het volgende codevoorbeeld worden de kenmerken in een knop en een tekstvak vergeleken om te zien of deze overeenkomen. Hierbij wordt ervan uitgegaan dat button1 en textBox1 zijn gemaakt op een formulier.
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
Opmerkingen
Een kenmerk kan ondersteuning bieden voor overeenkomende functies.