AttributeCollection.Contains 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
이 특성 컬렉션에 지정된 특성 또는 특성 배열이 있는지 여부를 확인합니다.
오버로드
| Name | Description |
|---|---|
| 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. 폼에서 생성된 것으로 button1textBox1 가정합니다.
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
설명
지정된 특성 형식이 컬렉션에 있고 지정된 특성의 값이 컬렉션에 있는 특성 인스턴스의 값과 같은 경우 이 컬렉션에는 지정된 특성이 있습니다.
메서드와 Contains 메서드의 Matches 차이점은 특성에서 메서드를 Match 호출하고 Contains 메서드를 호출한다는 Matches 것입니다Equals.
대부분의 특성에서 이러한 메서드는 동일한 작업을 수행합니다. 그러나 Match 여러 플래그가 있을 수 있는 특성의 경우 일반적으로 구현되므로 플래그가 충족되면 반환 true 됩니다. 예를 들어 부울 플래그 "SupportsSql", "SupportsOleDb" 및 "SupportsXml"이 있는 데이터 바인딩 특성을 고려합니다. 이 특성은 세 가지 데이터 바인딩 방법을 모두 지원하는 속성에 있을 수 있습니다. 프로그래머가 특정 접근 방식을 사용할 수 있는 경우에만 알고 있어야 하는 경우가 많으며, 세 가지 모두 알 수 있는 것은 아닙니다. 따라서 프로그래머가 프로그래머에 필요한 플래그만 포함하는 특성 인스턴스와 함께 사용할 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 단추의 특성이 텍스트 상자의 특성에 포함되어 있는지 여부를 확인합니다. 둘 다 button1textBox1 폼에서 만들어진 것으로 가정합니다.
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
설명
이 컬렉션에는 지정된 특성 형식이 모두 컬렉션에 있고 지정된 배열의 각 특성이 컬렉션의 특성과 같은 경우 지정된 특성 배열이 있습니다.