다음을 통해 공유


AttributeCollection 클래스

특성의 컬렉션을 나타냅니다.

네임스페이스: System.ComponentModel
어셈블리: System(system.dll)

구문

‘선언
<ComVisibleAttribute(True)> _
Public Class AttributeCollection
    Implements ICollection, IEnumerable
‘사용 방법
Dim instance As AttributeCollection
[ComVisibleAttribute(true)] 
public class AttributeCollection : ICollection, IEnumerable
[ComVisibleAttribute(true)] 
public ref class AttributeCollection : ICollection, IEnumerable
/** @attribute ComVisibleAttribute(true) */ 
public class AttributeCollection implements ICollection, IEnumerable
ComVisibleAttribute(true) 
public class AttributeCollection implements ICollection, IEnumerable

설명

AttributeCollection 클래스는 읽기 전용이며 특성을 추가 또는 제거하는 메서드를 구현하지 않습니다. 이러한 메서드를 구현하려면 이 클래스에서 상속해야 합니다.

Count 속성을 사용하여 컬렉션에 있는 특성의 개수를 확인합니다.

또한 이 클래스의 메서드를 사용하여 컬렉션의 내용에 대해 쿼리할 수도 있습니다. 지정된 특성 또는 특성 배열이 해당 컬렉션에 있는지 확인하려면 Contains 메서드를 호출합니다. 지정된 특성 또는 특성 배열이 해당 컬렉션에 있는지 확인하고 지정된 특성의 값이 컬렉션의 값과 같은지 확인하려면 Matches를 호출합니다.

대부분의 특성에서 기본값이 사용되는 경우에는 기본값이 요청되지 않지만, 특성에서 기본값이 사용되지 않는 경우에는 이 형식을 사용하는 인덱싱된 속성에서 Null 참조(Visual Basic의 경우 Nothing)이 반환됩니다. 자체 특성을 정의할 때 인수를 사용하지 않는 생성자를 제공하거나 "Default"라는 특성 형식의 공용 정적 필드를 정의하여 기본값을 선언할 수 있습니다.

참고

이 클래스에 적용되는 HostProtectionAttribute 특성의 Resources 속성 값은 Synchronization입니다. HostProtectionAttribute는 대개 아이콘을 두 번 클릭하거나, 명령을 입력하거나, 브라우저에서 URL을 입력하여 시작되는 데스크톱 응용 프로그램에 영향을 미치지 않습니다. 자세한 내용은 HostProtectionAttribute 클래스나 SQL Server 프로그래밍 및 호스트 보호 특성을 참조하십시오.

예제

첫 번째 코드 예제에서는 이 컬렉션에 BrowsableAttribute가 설정되어 있는지 확인합니다. 두 번째 예제에서는 단추에 대한 DescriptionAttribute의 실제 값을 가져옵니다. 두 예제를 진행하려면 폼에 button1textBox1이 모두 만들어져 있어야 합니다. 특성을 사용할 때는 특성이 설정되어 있는지 확인하거나 해당 값에 액세스해야 합니다.

Private Sub ContainsAttribute()
    ' Creates a new collection and assigns it the attributes for button1.
    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 'ContainsAttribute
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:
   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.set_Text("button1 has a browsable attribute.");
    }
    else {
        textBox1.set_Text("button1 does not have a browsable attribute.");
    }
} //ContainsAttribute
public function ContainsAttribute() {
    // Creates a new collection and assigns it the attributes for button1.
    var attributes : AttributeCollection;
    attributes = TypeDescriptor.GetAttributes(button1);
 
    // Sets an Attribute to the specific attribute.
    var myAttribute : BrowsableAttribute  = 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 GetAttributeValue()
    ' Creates a new collection and assigns it the attributes for button1.
    Dim attributes As AttributeCollection
    attributes = TypeDescriptor.GetAttributes(button1)
    
    ' Gets the designer attribute from the collection.
    Dim myDesigner As DesignerAttribute
    myDesigner = CType(attributes(GetType(DesignerAttribute)), DesignerAttribute)
    
    ' Prints the value of the attribute in a text box.
    textBox1.Text = myDesigner.DesignerTypeName
End Sub 'GetAttributeValue
private void GetAttributeValue() {
    // Creates a new collection and assigns it the attributes for button1.
    AttributeCollection attributes;
    attributes = TypeDescriptor.GetAttributes(button1);
 
    // Gets the designer attribute from the collection.
    DesignerAttribute myDesigner; 
    myDesigner = (DesignerAttribute)attributes[typeof(DesignerAttribute)];
 
    // Prints the value of the attribute in a text box.
    textBox1.Text = myDesigner.DesignerTypeName;
 }
private:
   void GetAttributeValue()
   {
      // Creates a new collection and assigns it the attributes for button1.
      AttributeCollection^ attributes;
      attributes = TypeDescriptor::GetAttributes( button1 );
      
      // Gets the designer attribute from the collection.
      DesignerAttribute^ myDesigner;
      myDesigner = (DesignerAttribute^)(attributes[DesignerAttribute::typeid]);
      
      // Prints the value of the attribute in a text box.
      textBox1->Text = myDesigner->DesignerTypeName;
   }
private void GetAttributeValue()
{
    // Creates a new collection and assigns it the attributes for button1.
    AttributeCollection attributes;
    attributes = TypeDescriptor.GetAttributes(button1);

    // Gets the designer attribute from the collection.
    DesignerAttribute myDesigner;
    myDesigner = ((DesignerAttribute)
        (attributes.get_Item(DesignerAttribute.class.ToType())));

    // Prints the value of the attribute in a text box.
    textBox1.set_Text(myDesigner.get_DesignerTypeName());
} //GetAttributeValue    
public function GetAttributeValue() {
    // Creates a new collection and assigns it the attributes for button1.
    var attributes : AttributeCollection ;
    attributes = TypeDescriptor.GetAttributes(button1);
 
    // Gets the designer attribute from the collection.
    var myDesigner : DesignerAttribute ; 
    myDesigner = DesignerAttribute(attributes[DesignerAttribute.GetType()]);
 
    // Prints the value of the attribute in a text box.
    if(myDesigner)
        textBox1.Text = myDesigner.DesignerTypeName;
 }

상속 계층 구조

System.Object
  System.ComponentModel.AttributeCollection

스레드로부터의 안전성

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

AttributeCollection 멤버
System.ComponentModel 네임스페이스
Attribute
BrowsableAttribute
DescriptionAttribute