AttributeCollection.Contains Methode

Definition

Bestimmt, ob das angegebene Attribut oder Attributarray in dieser Auflistung von Attributen enthalten ist.

Überlädt

Contains(Attribute)

Bestimmt, ob das angegebene Attribut in dieser Auflistung von Attributen enthalten ist.

Contains(Attribute[])

Bestimmt, ob diese Auflistung von Attributen sämtliche angegebenen Attribute im Attributarray enthält.

Contains(Attribute)

Quelle:
AttributeCollection.cs
Quelle:
AttributeCollection.cs
Quelle:
AttributeCollection.cs

Bestimmt, ob das angegebene Attribut in dieser Auflistung von Attributen enthalten ist.

public:
 bool Contains(Attribute ^ attribute);
public bool Contains (Attribute attribute);
public bool Contains (Attribute? attribute);
member this.Contains : Attribute -> bool
Public Function Contains (attribute As Attribute) As Boolean

Parameter

attribute
Attribute

Eine Attribute-Klasse, die in der Auflistung gesucht werden soll.

Gibt zurück

true, wenn die Auflistung das Attribut enthält oder das Standardattribut für den Attributtyp ist, andernfalls false.

Beispiele

Im folgenden Codebeispiel wird überprüft, ob die Auflistung auf BrowsableAttributetruefestgelegt ist. Es wird davon ausgegangen, dass 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 verfügt über das angegebene Attribut, 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 Matches Methoden und Contains besteht darin, dass Matches die Match -Methode für ein -Attribut aufruft und Contains die Equals -Methode aufruft.

Bei den meisten Attributen führen diese Methoden dasselbe aus. Für Attribute, die mehrere Flags aufweisen können, wird jedoch in der Regel implementiert, Match sodass es zurückgegeben true wird, wenn eines der Flags erfüllt ist. Betrachten Sie beispielsweise 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, ob ein bestimmter Ansatz verfügbar ist, nicht alle drei. Daher kann ein Programmierer mit einer Instanz des Attributs verwenden Match , die nur die Flags enthält, die der Programmierer benötigt.

Weitere Informationen

Gilt für:

Contains(Attribute[])

Quelle:
AttributeCollection.cs
Quelle:
AttributeCollection.cs
Quelle:
AttributeCollection.cs

Bestimmt, ob diese Auflistung von Attributen sämtliche angegebenen Attribute im Attributarray enthält.

public:
 bool Contains(cli::array <Attribute ^> ^ attributes);
public bool Contains (Attribute[] attributes);
public bool Contains (Attribute[]? attributes);
member this.Contains : Attribute[] -> bool
Public Function Contains (attributes As Attribute()) As Boolean

Parameter

attributes
Attribute[]

Ein Array vom Typ Attribute, das in der Auflistung gesucht werden soll.

Gibt zurück

true, wenn die Auflistung sämtliche Attribute enthält, andernfalls false.

Beispiele

Im folgenden Codebeispiel werden die Attribute in button1 und textBox1 verglichen, um festzustellen, ob die Attribute für die Schaltfläche in den Attributen für das Textfeld enthalten sind. Es wird davon ausgegangen, dass sowohl als textBox1 auch button1 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 verfügt über das angegebene Array von Attributen, wenn alle angegebenen Attributtypen in der Auflistung vorhanden sind und jedes Attribut im angegebenen Array mit einem Attribut in der Auflistung identisch ist.

Weitere Informationen

Gilt für: