AttributeCollection.Contains Yöntem

Tanım

Bu öznitelik koleksiyonunun belirtilen öznitelik veya öznitelik dizisine sahip olup olmadığını belirler.

Aşırı Yüklemeler

Contains(Attribute)

Bu öznitelik koleksiyonunun belirtilen özniteliğe sahip olup olmadığını belirler.

Contains(Attribute[])

Bu öznitelik koleksiyonunun öznitelik dizisinde belirtilen tüm öznitelikleri içerip içermediğini belirler.

Contains(Attribute)

Kaynak:
AttributeCollection.cs
Kaynak:
AttributeCollection.cs
Kaynak:
AttributeCollection.cs

Bu öznitelik koleksiyonunun belirtilen özniteliğe sahip olup olmadığını belirler.

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

Parametreler

attribute
Attribute

Koleksiyonda bulmak için bir Attribute .

Döndürülenler

true koleksiyon özniteliğini içeriyorsa veya öznitelik türü için varsayılan öznitelikse; aksi takdirde , false.

Örnekler

Aşağıdaki kod örneği, koleksiyonun olarak ayarlanıp ayarlanmadığını BrowsableAttributetruedenetler. Ve'nin button1textBox1 bir formda oluşturulduğunu varsayar.

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

Açıklamalar

Belirtilen öznitelik türü koleksiyonda varsa ve belirtilen özniteliğin değeri koleksiyondaki özniteliğin örneğinin değeriyle aynıysa, bu koleksiyon belirtilen özniteliğe sahiptir.

ve yöntemleri arasındaki Matches fark, özniteliğinde Match yöntemini çağıran Matches ve Contains yöntemini çağıran Equals yöntemdir.Contains

Çoğu öznitelik için bu yöntemler aynı şeyi yapar. Ancak, birden çok bayrağı olabilecek öznitelikler için, Match bayraklardan herhangi biri karşılandığında döndürülmesi true için genellikle uygulanır. Örneğin, "SupportsSql", "SupportsOleDb" ve "SupportsXml" Boole bayraklarına sahip bir veri bağlama özniteliğini göz önünde bulundurun. Bu öznitelik, üç veri bağlama yaklaşımını da destekleyen bir özellikte bulunabilir. Genellikle bir programcının yalnızca belirli bir yaklaşımın mevcut olup olmadığını bilmesi gerekir, üçünü de değil. Bu nedenle, bir programcı yalnızca programcının ihtiyaç duyduğu bayrakları içeren özniteliğin bir örneğiyle kullanabilir Match .

Ayrıca bkz.

Şunlara uygulanır

Contains(Attribute[])

Kaynak:
AttributeCollection.cs
Kaynak:
AttributeCollection.cs
Kaynak:
AttributeCollection.cs

Bu öznitelik koleksiyonunun öznitelik dizisinde belirtilen tüm öznitelikleri içerip içermediğini belirler.

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

Parametreler

attributes
Attribute[]

Koleksiyonda bulunacak tür Attribute dizisi.

Döndürülenler

true koleksiyon tüm öznitelikleri içeriyorsa; aksi takdirde , false.

Örnekler

Aşağıdaki kod örneği içindeki öznitelikleri button1 karşılaştırır ve textBox1 düğmesinin özniteliklerinin metin kutusunun özniteliklerinde bulunup bulunmadığını gösterir. Hem hem de button1textBox1 bir formda oluşturulduğunu varsayar.

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

Açıklamalar

Belirtilen öznitelik türlerinin tümü koleksiyonda varsa ve belirtilen dizideki her öznitelik koleksiyondaki bir öznitelikle aynıysa, bu koleksiyon belirtilen öznitelik dizisine sahiptir.

Ayrıca bkz.

Şunlara uygulanır