AttributeCollection.Contains Metodo

Definizione

Consente di determinare se questo insieme di attributi dispone dell'attributo o della matrice di attributi specificata.

Overload

Contains(Attribute)

Consente di determinare se questo insieme di attributi dispone dell'attributo specificato.

Contains(Attribute[])

Consente di determinare se questo insieme di attributi contiene tutti gli attributi specificati nella matrice di attributi.

Contains(Attribute)

Source:
AttributeCollection.cs
Source:
AttributeCollection.cs
Source:
AttributeCollection.cs

Consente di determinare se questo insieme di attributi dispone dell'attributo specificato.

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

Parametri

attribute
Attribute

Oggetto Attribute da individuare nell'insieme.

Restituisce

true se l'insieme contiene l'attributo o se è l'attributo predefinito per il tipo di attributo. In caso contrario, false.

Esempio

Nell'esempio di codice seguente viene verificato se l'insieme ha un BrowsableAttribute valore impostato su true. Si presuppone che button1 e textBox1 siano stati creati in un modulo.

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

Commenti

Questa raccolta ha l'attributo specificato se il tipo specificato di attributo esiste nella raccolta e se il valore dell'attributo specificato corrisponde al valore dell'istanza dell'attributo nella raccolta.

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, un programmatore deve 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

Contains(Attribute[])

Source:
AttributeCollection.cs
Source:
AttributeCollection.cs
Source:
AttributeCollection.cs

Consente di determinare se questo insieme di attributi contiene tutti gli attributi specificati nella matrice di attributi.

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

Parametri

attributes
Attribute[]

Matrice di tipo Attribute da individuare nell'insieme.

Restituisce

true se l'insieme contiene tutti gli attributi. In caso contrario, false.

Esempio

L'esempio di codice seguente confronta gli attributi in button1 e textBox1 per verificare se gli attributi per il pulsante sono contenuti negli attributi per la casella di testo. Presuppone che sia button1 che textBox1 siano stati creati in un modulo.

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

Commenti

Questa raccolta ha la matrice di attributi specificata se tutti i tipi di attributo specificati sono presenti nella raccolta e se ogni attributo nella matrice specificata è uguale a un attributo nella raccolta.

Vedi anche

Si applica a