AttributeCollection.Contains Methode

Definitie

Bepaalt of deze verzameling kenmerken het opgegeven kenmerk of de matrix van kenmerken heeft.

Overloads

Name Description
Contains(Attribute)

Bepaalt of deze verzameling kenmerken het opgegeven kenmerk heeft.

Contains(Attribute[])

Bepaalt of deze kenmerkverzameling alle opgegeven kenmerken in de kenmerkmatrix bevat.

Contains(Attribute)

Bron:
AttributeCollection.cs
Bron:
AttributeCollection.cs
Bron:
AttributeCollection.cs
Bron:
AttributeCollection.cs
Bron:
AttributeCollection.cs

Bepaalt of deze verzameling kenmerken het opgegeven kenmerk heeft.

public:
 bool Contains(Attribute ^ attribute);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")]
public bool Contains(Attribute? attribute);
public bool Contains(Attribute attribute);
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")>]
member this.Contains : Attribute -> bool
member this.Contains : Attribute -> bool
Public Function Contains (attribute As Attribute) As Boolean

Parameters

attribute
Attribute

Een Attribute te vinden in de verzameling.

Retouren

true als de verzameling het kenmerk bevat of het standaardkenmerk is voor het type kenmerk; anders, false.

Kenmerken

Voorbeelden

In het volgende codevoorbeeld wordt gecontroleerd of de verzameling is BrowsableAttribute ingesteld op true. Hierbij wordt ervan uitgegaan dat button1 en textBox1 zijn gemaakt op een formulier.

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

Opmerkingen

Deze verzameling heeft het opgegeven kenmerk als het opgegeven type kenmerk bestaat in de verzameling en als de waarde van het opgegeven kenmerk gelijk is aan de waarde van het exemplaar van het kenmerk in de verzameling.

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 alle drie de methoden voor gegevensbinding ondersteunt. 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

Contains(Attribute[])

Bron:
AttributeCollection.cs
Bron:
AttributeCollection.cs
Bron:
AttributeCollection.cs
Bron:
AttributeCollection.cs
Bron:
AttributeCollection.cs

Bepaalt of deze kenmerkverzameling alle opgegeven kenmerken in de kenmerkmatrix bevat.

public:
 bool Contains(cli::array <Attribute ^> ^ attributes);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")]
public bool Contains(Attribute[]? attributes);
public bool Contains(Attribute[] attributes);
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")>]
member this.Contains : Attribute[] -> bool
member this.Contains : Attribute[] -> bool
Public Function Contains (attributes As Attribute()) As Boolean

Parameters

attributes
Attribute[]

Een matrix van het type Attribute dat u in de verzameling kunt vinden.

Retouren

true als de verzameling alle kenmerken bevat; anders, false.

Kenmerken

Voorbeelden

Het volgende codevoorbeeld vergelijkt de kenmerken in button1 en textBox1 om te zien of de kenmerken voor de knop zijn opgenomen in de kenmerken voor het tekstvak. Hierbij wordt ervan uitgegaan dat zowel button1 als textBox1 op een formulier zijn gemaakt.

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

Opmerkingen

Deze verzameling heeft de opgegeven matrix met kenmerken als alle opgegeven kenmerktypen aanwezig zijn in de verzameling en als elk kenmerk in de opgegeven matrix hetzelfde is als een kenmerk in de verzameling.

Zie ook

Van toepassing op