Share via


AttributeCollection.Matches Metode

Definisi

Menentukan apakah atribut atau array atribut yang ditentukan sama dengan atribut atau array atribut dalam koleksi.

Overload

Matches(Attribute)

Menentukan apakah atribut yang ditentukan sama dengan atribut dalam koleksi.

Matches(Attribute[])

Menentukan apakah atribut dalam array yang ditentukan sama dengan atribut dalam koleksi.

Matches(Attribute)

Sumber:
AttributeCollection.cs
Sumber:
AttributeCollection.cs
Sumber:
AttributeCollection.cs

Menentukan apakah atribut yang ditentukan sama dengan atribut dalam koleksi.

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

Parameter

attribute
Attribute

Instans Attribute untuk membandingkan dengan atribut dalam koleksi ini.

Mengembalikan

true jika atribut terkandung dalam koleksi dan memiliki nilai yang sama dengan atribut dalam koleksi; jika tidak, false.

Contoh

Contoh kode berikut memverifikasi bahwa BrowsableAttribute adalah anggota koleksi dan telah diatur ke true. Ini mengasumsikan bahwa button1 dan textBox1 telah dibuat pada formulir.

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

Keterangan

Atribut dapat memberikan dukungan untuk pencocokan.

Perbedaan antara Matches metode dan Contains adalah yang Matches memanggil Match metode pada atribut , dan Contains memanggil Equals metode .

Untuk sebagian besar atribut, metode ini melakukan hal yang sama. Namun, untuk atribut yang mungkin memiliki beberapa bendera, Match biasanya diimplementasikan sehingga kembali true jika salah satu bendera terpenuhi. Misalnya, pertimbangkan atribut pengikatan data dengan bendera Boolean "SupportsSql", "SupportsOleDb", dan "SupportsXml". Atribut ini mungkin ada pada properti yang mendukung ketiga pendekatan pengikatan data. Akan sering terjadi bahwa programmer perlu tahu hanya jika pendekatan tertentu tersedia, bukan ketiganya. Oleh karena itu, programmer dapat menggunakan Match dengan instans atribut yang hanya berisi bendera yang dibutuhkan programmer.

Lihat juga

Berlaku untuk

Matches(Attribute[])

Sumber:
AttributeCollection.cs
Sumber:
AttributeCollection.cs
Sumber:
AttributeCollection.cs

Menentukan apakah atribut dalam array yang ditentukan sama dengan atribut dalam koleksi.

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

Parameter

attributes
Attribute[]

Array MemberAttributes untuk dibandingkan dengan atribut dalam koleksi ini.

Mengembalikan

true jika semua atribut dalam array terkandung dalam koleksi dan memiliki nilai yang sama dengan atribut dalam koleksi; jika tidak, false.

Contoh

Contoh kode berikut membandingkan atribut dalam tombol dan kotak teks untuk melihat apakah atribut cocok. Ini mengasumsikan bahwa button1 dan textBox1 telah dibuat pada formulir.

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

Keterangan

Atribut dapat memberikan dukungan untuk pencocokan.

Lihat juga

Berlaku untuk