AttributeCollection.Contains メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
この属性のコレクションに、指定した属性または属性の配列があるかどうかを判断します。
オーバーロード
| 名前 | 説明 |
|---|---|
| Contains(Attribute) |
この属性のコレクションに指定した属性があるかどうかを判断します。 |
| Contains(Attribute[]) |
この属性コレクションに、属性配列内の指定されたすべての属性が含まれているかどうかを判断します。 |
Contains(Attribute)
この属性のコレクションに指定した属性があるかどうかを判断します。
public:
bool Contains(Attribute ^ attribute);
public bool Contains(Attribute attribute);
member this.Contains : Attribute -> bool
Public Function Contains (attribute As Attribute) As Boolean
パラメーター
返品
true コレクションに属性が含まれている場合、または属性の型の既定の属性である場合。それ以外の場合は false。
例
次のコード例では、コレクションに BrowsableAttribute が true に設定されているかどうかを確認します。 フォームに button1 と textBox1 が作成されていることを前提としています。
protected:
void ContainsAttribute()
{
// Creates a new collection and assigns it the attributes for button1.
AttributeCollection^ attributes;
attributes = TypeDescriptor::GetAttributes( button1 );
// Sets an Attribute to the specific attribute.
BrowsableAttribute^ myAttribute = BrowsableAttribute::Yes;
if ( attributes->Contains( myAttribute ) )
{
textBox1->Text = "button1 has a browsable attribute.";
}
else
{
textBox1->Text = "button1 does not have a browsable attribute.";
}
}
private void ContainsAttribute() {
// Creates a new collection and assigns it the attributes for button1.
AttributeCollection attributes;
attributes = TypeDescriptor.GetAttributes(button1);
// Sets an Attribute to the specific attribute.
BrowsableAttribute myAttribute = BrowsableAttribute.Yes;
if (attributes.Contains(myAttribute))
textBox1.Text = "button1 has a browsable attribute.";
else
textBox1.Text = "button1 does not have a browsable attribute.";
}
Private Sub ContainsAttribute
' Creates a new collection and assigns it the attributes for button.
Dim attributes As AttributeCollection
attributes = TypeDescriptor.GetAttributes(button1)
' Sets an Attribute to the specific attribute.
Dim myAttribute As BrowsableAttribute = BrowsableAttribute.Yes
If Attributes.Contains(myAttribute) Then
textBox1.Text = "button1 has a browsable attribute."
Else
textBox1.Text = "button1 does not have a browsable attribute."
End If
End Sub
注釈
指定した属性の型がコレクション内に存在し、指定した属性の値がコレクション内の属性のインスタンスの値と同じである場合、このコレクションには、指定した属性があります。
MatchesメソッドとContains メソッドの違いは、Matches属性に対して Match メソッドを呼び出し、ContainsEquals メソッドを呼び出す点です。
ほとんどの属性では、これらのメソッドは同じことを行います。 ただし、複数のフラグを持つ可能性がある属性の場合、 Match は通常、いずれかのフラグが満たされた場合に true を返すように実装されます。 たとえば、ブール値フラグ "SupportsSql"、"SupportsOleDb"、および "SupportsXml" を持つデータ バインディング属性を考えてみましょう。 この属性は、3 つのデータ バインディング アプローチをすべてサポートするプロパティに存在する場合があります。 多くの場合、プログラマは、3 つすべてではなく、特定のアプローチが利用できる場合にのみ知る必要があります。 したがって、プログラマは、プログラマが必要とするフラグのみを含む属性のインスタンスで Match を使用できます。
こちらもご覧ください
適用対象
Contains(Attribute[])
この属性コレクションに、属性配列内の指定されたすべての属性が含まれているかどうかを判断します。
public:
bool Contains(cli::array <Attribute ^> ^ attributes);
public bool Contains(Attribute[] attributes);
member this.Contains : Attribute[] -> bool
Public Function Contains (attributes As Attribute()) As Boolean
パラメーター
返品
true コレクションにすべての属性が含まれている場合。それ以外の場合は false。
例
次のコード例では、 button1 の属性と textBox1 を比較して、ボタンの属性がテキスト ボックスの属性に含まれているかどうかを確認します。 フォームに button1 と textBox1 の両方が作成されていることを前提としています。
private:
void ContainsAttributes()
{
// 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 are the attributes for textBox1.
array<Attribute^>^ myAttrArray = gcnew array<Attribute^>(100);
TypeDescriptor::GetAttributes( textBox1 )->CopyTo( myAttrArray, 0 );
if ( myCollection->Contains( myAttrArray ) )
{
textBox1->Text = "Both the button and text box have the same attributes.";
}
else
{
textBox1->Text = "The button and the text box do not have the same attributes.";
}
}
private void ContainsAttributes() {
// 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 are the attributes for textBox1.
Attribute[] myAttrArray = new Attribute[100];
TypeDescriptor.GetAttributes(textBox1).CopyTo(myAttrArray, 0);
if (myCollection.Contains(myAttrArray))
textBox1.Text = "Both the button and text box have the same attributes.";
else
textBox1.Text = "The button and the text box do not have the same attributes.";
}
Private Sub ContainsAttributes()
' 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 are the attributes for textBox1.
Dim myAttrArray(100) As Attribute
TypeDescriptor.GetAttributes(textBox1).CopyTo(myAttrArray, 0)
If myCollection.Contains(myAttrArray) Then
textBox1.Text = "Both the button and text box have the same attributes."
Else
textBox1.Text = "The button and the text box do not have the same attributes."
End If
End Sub
注釈
指定されたすべての属性型がコレクション内に存在し、指定した配列内の各属性がコレクション内の属性と同じである場合、このコレクションには、指定した属性の配列があります。