AttributeCollection.Matches 方法

定義

判斷指定屬性或屬性陣列是否和集合中的屬性或屬性陣列相同。

多載

Matches(Attribute)

判斷指定屬性是否和集合中的屬性相同。

Matches(Attribute[])

判斷指定陣列中的屬性是否與集合中的屬性相同。

Matches(Attribute)

來源:
AttributeCollection.cs
來源:
AttributeCollection.cs
來源:
AttributeCollection.cs

判斷指定屬性是否和集合中的屬性相同。

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

參數

attribute
Attribute

要與這個集合中屬性相比較之 Attribute 的執行個體。

傳回

如果屬性包含在集合中,並且具有和集合中屬性相同的值,則為 true,否則為 false

範例

下列程式代碼範例會 BrowsableAttribute 驗證 是集合的成員,而且它已設定為 true。 它會假設 button1 已在表單上建立 和 textBox1

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

備註

屬性可以提供比對的支援。

和方法之間的差異Matches在於呼叫 MatchMatches 屬性上的 方法,並Contains呼叫 Equals 方法。Contains

對於大部分的屬性,這些方法會執行相同的動作。 不過,對於可能有多個旗標的屬性, Match 通常會實作 ,以便在滿足任何旗標時傳回 true 。 例如,請考慮具有布爾值旗標 「SupportsSql」、“SupportsOleDb” 和 “SupportsXml” 的數據系結屬性。 此屬性可能存在於支援這三種數據系結方法的屬性上。 程序設計人員通常只需要知道特定方法是否可用,而不是這三種方法。 因此,程式設計人員可以搭配只包含程式設計人員所需之旗標的屬性實例使用 Match

另請參閱

適用於

Matches(Attribute[])

來源:
AttributeCollection.cs
來源:
AttributeCollection.cs
來源:
AttributeCollection.cs

判斷指定陣列中的屬性是否與集合中的屬性相同。

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

參數

attributes
Attribute[]

要與這個集合中屬性相比較之 MemberAttributes 的陣列。

傳回

如果陣列中的所有屬性都包含在集合中,並且具有和集合中屬性相同的值,則為 true,否則為 false

範例

下列程式代碼範例會比較按鈕和文字框中的屬性,以查看它們是否相符。 它會假設 button1 已在表單上建立 和 textBox1

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

備註

屬性可以提供比對的支援。

另請參閱

適用於