AttributeCollection.Contains Methode
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Bestimmt, ob diese Auflistung von Attributen das angegebene Attribut oder Array von Attributen aufweist.
Überlädt
| Name | Beschreibung |
|---|---|
| Contains(Attribute) |
Bestimmt, ob diese Auflistung von Attributen das angegebene Attribut aufweist. |
| Contains(Attribute[]) |
Bestimmt, ob diese Attributauflistung alle angegebenen Attribute im Attributarray enthält. |
Contains(Attribute)
Bestimmt, ob diese Auflistung von Attributen das angegebene Attribut aufweist.
public:
bool Contains(Attribute ^ attribute);
public bool Contains(Attribute attribute);
member this.Contains : Attribute -> bool
Public Function Contains (attribute As Attribute) As Boolean
Parameter
Gibt zurück
truewenn die Auflistung das Attribut enthält oder das Standard-Attribut für den Typ des Attributs ist; andernfalls . false
Beispiele
Im folgenden Codebeispiel wird überprüft, ob die Auflistung auf . > festgelegt button1 und textBox1 auf einem Formular erstellt wurden.
protected:
void ContainsAttribute()
{
// Creates a new collection and assigns it the attributes for button1.
AttributeCollection^ attributes;
attributes = TypeDescriptor::GetAttributes( button1 );
// Sets an Attribute to the specific attribute.
BrowsableAttribute^ myAttribute = BrowsableAttribute::Yes;
if ( attributes->Contains( myAttribute ) )
{
textBox1->Text = "button1 has a browsable attribute.";
}
else
{
textBox1->Text = "button1 does not have a browsable attribute.";
}
}
private void ContainsAttribute() {
// Creates a new collection and assigns it the attributes for button1.
AttributeCollection attributes;
attributes = TypeDescriptor.GetAttributes(button1);
// Sets an Attribute to the specific attribute.
BrowsableAttribute myAttribute = BrowsableAttribute.Yes;
if (attributes.Contains(myAttribute))
textBox1.Text = "button1 has a browsable attribute.";
else
textBox1.Text = "button1 does not have a browsable attribute.";
}
Private Sub ContainsAttribute
' Creates a new collection and assigns it the attributes for button.
Dim attributes As AttributeCollection
attributes = TypeDescriptor.GetAttributes(button1)
' Sets an Attribute to the specific attribute.
Dim myAttribute As BrowsableAttribute = BrowsableAttribute.Yes
If Attributes.Contains(myAttribute) Then
textBox1.Text = "button1 has a browsable attribute."
Else
textBox1.Text = "button1 does not have a browsable attribute."
End If
End Sub
Hinweise
Diese Auflistung weist das angegebene Attribut auf, wenn der angegebene Attributtyp in der Auflistung vorhanden ist und der Wert des angegebenen Attributs mit dem Wert der Instanz des Attributs in der Auflistung identisch ist.
Der Unterschied zwischen den Methoden und Contains den Matches Methoden besteht darin, dass Matches die Match Methode für ein Attribut aufgerufen und Contains die Equals Methode aufgerufen wird.
Bei den meisten Attributen führen diese Methoden dasselbe aus. Bei Attributen, die möglicherweise mehrere Flags aufweisen, wird jedoch in der Regel implementiert, sodass sie zurückgegeben true wird, Match wenn eines der Flags erfüllt ist. Betrachten Sie z. B. ein Datenbindungsattribut mit den booleschen Flags "SupportsSql", "SupportsOleDb" und "SupportsXml". Dieses Attribut kann für eine Eigenschaft vorhanden sein, die alle drei Datenbindungsansätze unterstützt. Es wird oft der Fall sein, dass ein Programmierer nur wissen muss, wenn ein bestimmter Ansatz verfügbar ist, nicht alle drei. Daher könnte ein Programmierer mit einer Instanz des Attributs verwenden Match , das nur die Flags enthält, die der Programmierer benötigt.
Weitere Informationen
Gilt für:
Contains(Attribute[])
Bestimmt, ob diese Attributauflistung alle angegebenen Attribute im Attributarray enthält.
public:
bool Contains(cli::array <Attribute ^> ^ attributes);
public bool Contains(Attribute[] attributes);
member this.Contains : Attribute[] -> bool
Public Function Contains (attributes As Attribute()) As Boolean
Parameter
Gibt zurück
truewenn die Auflistung alle Attribute enthält; andernfalls . false
Beispiele
Im folgenden Codebeispiel werden die Attribute button1 verglichen und textBox1 überprüft, ob die Attribute für die Schaltfläche in den Attributen für das Textfeld enthalten sind. Es wird davon ausgegangen, dass beide und button1textBox1 auf einem Formular erstellt wurden.
private:
void ContainsAttributes()
{
// 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 are the attributes for textBox1.
array<Attribute^>^ myAttrArray = gcnew array<Attribute^>(100);
TypeDescriptor::GetAttributes( textBox1 )->CopyTo( myAttrArray, 0 );
if ( myCollection->Contains( myAttrArray ) )
{
textBox1->Text = "Both the button and text box have the same attributes.";
}
else
{
textBox1->Text = "The button and the text box do not have the same attributes.";
}
}
private void ContainsAttributes() {
// 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 are the attributes for textBox1.
Attribute[] myAttrArray = new Attribute[100];
TypeDescriptor.GetAttributes(textBox1).CopyTo(myAttrArray, 0);
if (myCollection.Contains(myAttrArray))
textBox1.Text = "Both the button and text box have the same attributes.";
else
textBox1.Text = "The button and the text box do not have the same attributes.";
}
Private Sub ContainsAttributes()
' 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 are the attributes for textBox1.
Dim myAttrArray(100) As Attribute
TypeDescriptor.GetAttributes(textBox1).CopyTo(myAttrArray, 0)
If myCollection.Contains(myAttrArray) Then
textBox1.Text = "Both the button and text box have the same attributes."
Else
textBox1.Text = "The button and the text box do not have the same attributes."
End If
End Sub
Hinweise
Diese Auflistung weist das angegebene Array von Attributen auf, wenn alle angegebenen Attributtypen in der Auflistung vorhanden sind und jedes Attribut im angegebenen Array mit einem Attribut in der Auflistung identisch ist.