次の方法で共有


AttributeCollection.Matches メソッド (Attribute)

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

Overloads Public Function Matches( _
   ByVal attribute As Attribute _) As Boolean
[C#]
public bool Matches(Attributeattribute);
[C++]
public: bool Matches(Attribute* attribute);
[JScript]
public function Matches(
   attribute : Attribute) : Boolean;

パラメータ

  • attribute
    コレクション内の属性と比較する対象の Attribute のインスタンス。

戻り値

指定した属性がコレクションに格納されていて、その値がコレクション内の属性の値と同じ場合は true 。それ以外の場合は false

解説

属性が一致するかどうかを確認する機能がサポートされています。

MatchesContains 間の違いは、 Matches が属性の Match メソッドを呼び出すのに対して、 ContainsEquals メソッドを呼び出す点です。

ほとんどの属性で、これらのメソッドは同じ処理を実行します。ただし、フラグを複数持つことができる属性では、通常 Match が実装されているため、いずれかのフラグが条件を満たしている場合は true が返されます。たとえば、ブール フラグ "SupportsSql"、"SupportsOleDb"、および "SupportsXml" を持つデータ連結属性について考えてみましょう。この属性は、すべてのデータ連結方法をサポートしているプロパティに存在することがあります。プログラマは、3 つすべてではなく、特定の方法が使用できるかどうかを知るだけで十分な場合もあります。このため、プログラマは必要なフラグだけを格納している属性のインスタンスで、 Match を使用できます。

使用例

BrowsableAttribute がコレクションのメンバであり、その値が true に設定されていることを確認する例を次に示します。この例は、フォーム上に button1textBox1 が作成されていることを前提としています。

 
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
End Class

[C#] 
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.";
 }


[C++] 
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 = S"button1 is browsable.";
        else
            textBox1->Text = S"button1 is not browsable.";
    }


[JScript] 
private function MatchesAttribute() {
    // Creates a new collection and assigns it the attributes for button1.
    var attributes : AttributeCollection;
    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.";
    Console.WriteLine(textBox1.Text);
 }

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

AttributeCollection クラス | AttributeCollection メンバ | System.ComponentModel 名前空間 | AttributeCollection.Matches オーバーロードの一覧 | Attribute | BrowsableAttribute