AttributeCollection.Matches メソッド

定義

指定した属性または属性の配列が、コレクション内の属性または属性の配列と同じかどうかを判断します。

オーバーロード

名前 説明
Matches(Attribute)

指定した属性がコレクション内の属性と同じかどうかを判断します。

Matches(Attribute[])

指定した配列内の属性がコレクション内の属性と同じかどうかを判断します。

Matches(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に設定されていることを確認します。 フォームに button1textBox1 が作成されていることを前提としています。

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メソッドとContains メソッドの違いは、Matches属性に対して Match メソッドを呼び出し、ContainsEquals メソッドを呼び出す点です。

ほとんどの属性では、これらのメソッドは同じことを行います。 ただし、複数のフラグを持つ可能性がある属性の場合、 Match は通常、いずれかのフラグが満たされた場合に true を返すように実装されます。 たとえば、ブール値フラグ "SupportsSql"、"SupportsOleDb"、および "SupportsXml" を持つデータ バインディング属性を考えてみましょう。 この属性は、3 つのデータ バインディング アプローチをすべてサポートするプロパティに存在する場合があります。 多くの場合、プログラマは、3 つすべてではなく、特定のアプローチが利用できる場合にのみ知る必要があります。 したがって、プログラマは、プログラマが必要とするフラグのみを含む属性のインスタンスで Match を使用できます。

こちらもご覧ください

適用対象

Matches(Attribute[])

指定した配列内の属性がコレクション内の属性と同じかどうかを判断します。

public:
 bool Matches(cli::array <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

次のコード例では、ボタンとテキスト ボックスの属性を比較して、一致するかどうかを確認します。 フォームに button1textBox1 が作成されていることを前提としています。

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

注釈

属性は、照合のサポートを提供できます。

こちらもご覧ください

適用対象