AttributeCollection.Matches Yöntem

Tanım

Belirtilen öznitelik veya öznitelik dizisinin koleksiyondaki öznitelik veya öznitelik dizisiyle aynı olup olmadığını belirler.

Aşırı Yüklemeler

Name Description
Matches(Attribute)

Belirtilen özniteliğin koleksiyondaki bir öznitelikle aynı olup olmadığını belirler.

Matches(Attribute[])

Belirtilen dizideki özniteliklerin koleksiyondaki özniteliklerle aynı olup olmadığını belirler.

Matches(Attribute)

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

Belirtilen özniteliğin koleksiyondaki bir öznitelikle aynı olup olmadığını belirler.

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

Parametreler

attribute
Attribute

Bu koleksiyondaki özniteliklerle karşılaştırmak için bir örneği Attribute .

Döndürülenler

true özniteliği koleksiyon içinde yer alırsa ve koleksiyondaki öznitelikle aynı değere sahipse; aksi takdirde , false.

Örnekler

Aşağıdaki kod örneği, öğesinin BrowsableAttribute koleksiyonun bir üyesi olduğunu ve olarak ayarlandığını truedoğrular. Ve'nin button1textBox1 bir formda oluşturulduğunu varsayar.

private:
   void MatchesAttribute()
   {
      // Creates a new collection and assigns it the attributes for button1.
      AttributeCollection^ attributes;
      attributes = TypeDescriptor::GetAttributes( button1 );
      
      // Checks to see if the browsable attribute is true.
      if ( attributes->Matches( BrowsableAttribute::Yes ) )
      {
         textBox1->Text = "button1 is browsable.";
      }
      else
      {
         textBox1->Text = "button1 is not browsable.";
      }
   }
private void MatchesAttribute() {
    // Creates a new collection and assigns it the attributes for button1.
    AttributeCollection attributes;
    attributes = TypeDescriptor.GetAttributes(button1);

    // Checks to see if the browsable attribute is true.
    if (attributes.Matches(BrowsableAttribute.Yes))
       textBox1.Text = "button1 is browsable.";
    else
       textBox1.Text = "button1 is not browsable.";
 }
Private Sub MatchesAttribute
    ' Creates a new collection and assigns it the attributes for button
    Dim attributes As AttributeCollection
    attributes = TypeDescriptor.GetAttributes(button1)

    ' Checks to see if the browsable attribute is true.
    If attributes.Matches(BrowsableAttribute.Yes) Then
        textBox1.Text = "button1 is browsable."
    Else
        textBox1.Text = "button1 is not browsable."
    End If
End Sub

Açıklamalar

Öznitelik, eşleştirme için destek sağlayabilir.

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

Çoğu öznitelik için bu yöntemler aynı şeyi yapar. Ancak, birden çok bayrağı olabilecek öznitelikler için genellikle Match , bayraklardan herhangi biri karşılandığında döndürülmesi true için 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ü birden 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

Matches(Attribute[])

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

Belirtilen dizideki özniteliklerin koleksiyondaki özniteliklerle aynı olup olmadığını belirler.

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

Parametreler

attributes
Attribute[]

Bu koleksiyondaki özniteliklerle karşılaştıracak bir dizisi MemberAttributes .

Döndürülenler

true dizideki tüm öznitelikler koleksiyonda yer alırsa ve koleksiyondaki özniteliklerle aynı değerlere sahipse; aksi takdirde , false.

Örnekler

Aşağıdaki kod örneği, bir düğmedeki ve metin kutusundaki öznitelikleri karşılaştırarak bunların eşleşip eşleşmediğini gösterir. Ve'nin button1textBox1 bir formda oluşturulduğunu varsayar.

private:
   void MatchesAttributes()
   {
      // 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 match the attributes for textBox1.
      array<Attribute^>^ myAttrArray = gcnew array<Attribute^>(100);
      TypeDescriptor::GetAttributes( textBox1 )->CopyTo( myAttrArray, 0 );
      if ( myCollection->Matches( myAttrArray ) )
      {
         textBox1->Text = "The attributes in the button and text box match.";
      }
      else
      {
         textBox1->Text = "The attributes in the button and text box do not match.";
      }
   }
private void MatchesAttributes() {
   // 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 match the attributes for textBox1.
   Attribute[] myAttrArray = new Attribute[100];
   TypeDescriptor.GetAttributes(textBox1).CopyTo(myAttrArray, 0);
   if (myCollection.Matches(myAttrArray))
      textBox1.Text = "The attributes in the button and text box match.";
   else
      textBox1.Text = "The attributes in the button and text box do not match.";
}
Private Sub MatchesAttributes()
    ' 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 match the attributes.
    ' for textBox1.
    Dim myAttrArray(100) As Attribute
    TypeDescriptor.GetAttributes(textBox1).CopyTo(myAttrArray, 0)
    If myCollection.Matches(myAttrArray) Then
        textBox1.Text = "The attributes in the button and text box match."
    Else
        textBox1.Text = "The attributes in the button and text box do not match."
    End If
End Sub

Açıklamalar

Öznitelik, eşleştirme için destek sağlayabilir.

Ayrıca bkz.

Şunlara uygulanır