TypeAttributes 열거형

정의

형식 특성을 지정합니다.

이 열거형은 멤버 값의 비트 조합을 지원합니다.

public enum class TypeAttributes
[System.Flags]
public enum TypeAttributes
[System.Flags]
[System.Serializable]
public enum TypeAttributes
[System.Flags]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum TypeAttributes
[<System.Flags>]
type TypeAttributes = 
[<System.Flags>]
[<System.Serializable>]
type TypeAttributes = 
[<System.Flags>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type TypeAttributes = 
Public Enum TypeAttributes
상속
TypeAttributes
특성

필드

Abstract 128

형식을 추상으로 지정합니다.

AnsiClass 0

LPTSTR가 ANSI로 해석됩니다.

AutoClass 131072

LPTSTR가 자동으로 해석됩니다.

AutoLayout 0

클래스 필드가 공용 언어 런타임에 의해 자동으로 레이아웃되도록 지정합니다.

BeforeFieldInit 1048576

형식을 호출하는 정적 메서드가 시스템에서 해당 형식을 강제로 초기화하지 않도록 지정합니다.

Class 0

형식을 클래스로 지정합니다.

ClassSemanticsMask 32

클래스 기능 정보를 지정합니다. 현재 클래스에 컨텍스트를 추가(활성)할 수 있습니다.

CustomFormatClass 196608

LPSTR은 NotSupportedException이 throw될 가능성을 비롯하여 구현 방식에 따라 다르게 해석됩니다. .NET Framework Microsoft 구현에는 사용되지 않습니다.

CustomFormatMask 12582912

네이티브 interop에 대한 비표준 인코딩 정보를 검색하는 데 사용됩니다. 이러한 2비트 값의 의미는 지정되어 있지 않습니다. .NET Framework Microsoft 구현에는 사용되지 않습니다.

ExplicitLayout 16

클래스 필드를 지정한 간격으로 레이아웃하도록 지정합니다.

HasSecurity 262144

형식에 관련 보안이 있습니다.

Import 4096

클래스나 인터페이스를 다른 모듈에서 가져오도록 지정합니다.

Interface 32

형식을 인터페이스로 지정합니다.

LayoutMask 24

클래스 레이아웃 정보를 지정합니다.

NestedAssembly 5

클래스를 어셈블리 표시 유형으로 중첩시켜 해당 클래스의 어셈블리 내의 메서드에서만 액세스할 수 있도록 지정합니다.

NestedFamANDAssem 6

클래스를 어셈블리와 패밀리 표시 유형으로 중첩시켜 해당 클래스의 패밀리와 어셈블리의 교집합에 있는 메서드에서만 액세스할 수 있도록 지정합니다.

NestedFamily 4

클래스를 패밀리 표시 유형으로 중첩시켜 클래스의 고유한 형식과 다른 파생 형식 내의 메서드에서만 액세스할 수 있도록 지정합니다.

NestedFamORAssem 7

클래스를 패밀리나 어셈블리 표시 유형으로 중첩시켜 해당 클래스의 패밀리나 어셈블리의 합집합 속에 있는 메서드에서만 액세스할 수 있도록 지정합니다.

NestedPrivate 3

클래스를 프라이빗 표시 유형으로 중첩시키도록 지정합니다.

NestedPublic 2

클래스를 공용 표시 유형으로 중첩시키도록 지정합니다.

NotPublic 0

클래스를 공용이 아니도록 지정합니다.

Public 1

클래스를 공용이 되도록 지정합니다.

ReservedMask 264192

런타임에 사용하도록 예약된 특성입니다.

RTSpecialName 2048

런타임에서 이름 인코딩을 검사해야 합니다.

Sealed 256

클래스를 고정시켜 확장되지 않도록 지정합니다.

SequentialLayout 8

메타 데이터로 필드가 발생하도록 하기 위해 클래스 필드를 순차적으로 레이아웃시키도록 지정합니다.

Serializable 8192

클래스를 serialize할 수 있도록 지정합니다.

SpecialName 1024

이름을 사용하여 설명하는 방법으로 클래스를 지정합니다.

StringFormatMask 196608

기본 상호 운용성의 문자열 정보를 검색하는 데 사용됩니다.

UnicodeClass 65536

LPTSTR가 유니코드로 해석됩니다.

VisibilityMask 7

형식 표시 유형 정보를 지정합니다.

WindowsRuntime 16384

Windows 런타임 형식을 지정합니다.

예제

다음 예제에서는 다양한 형식을 나타내는 개체의 Attributes Type 속성 값을 검색한 다음 개별 특성 플래그가 설정되었는지 여부를 확인합니다.

using System;
using System.Reflection;

internal struct S
{
    public int X;
}

public abstract class Example
{
    protected sealed class NestedClass {}

    public interface INested {}

    public static void Main()
    {
        // Create an array of types.
        Type[] types = { typeof(Example), typeof(NestedClass),
                         typeof(INested), typeof(S) };

        foreach (var t in types) 
        {
           Console.WriteLine("Attributes for type {0}:", t.Name);

           TypeAttributes attr = t.Attributes;

           // To test for visibility attributes, you must use the visibility mask.
           TypeAttributes visibility = attr & TypeAttributes.VisibilityMask;
           switch (visibility)
           {
               case TypeAttributes.NotPublic:
                   Console.WriteLine("   ...is not public");
                   break;
               case TypeAttributes.Public:
                   Console.WriteLine("   ...is public");
                   break;
               case TypeAttributes.NestedPublic:
                   Console.WriteLine("   ...is nested and public");
                   break;
               case TypeAttributes.NestedPrivate:
                   Console.WriteLine("   ...is nested and private");
                   break;
               case TypeAttributes.NestedFamANDAssem:
                   Console.WriteLine("   ...is nested, and inheritable only within the assembly" +
                      "\n         (cannot be declared in C#)");
                   break;
               case TypeAttributes.NestedAssembly:
                   Console.WriteLine("   ...is nested and internal");
                   break;
               case TypeAttributes.NestedFamily:
                   Console.WriteLine("   ...is nested and protected");
                   break;
               case TypeAttributes.NestedFamORAssem:
                   Console.WriteLine("   ...is nested and protected internal");
                   break;
           }

           // Use the layout mask to test for layout attributes.
           TypeAttributes layout = attr & TypeAttributes.LayoutMask;
           switch (layout)
           {
               case TypeAttributes.AutoLayout:
                   Console.WriteLine("   ...is AutoLayout");
                   break;
               case TypeAttributes.SequentialLayout:
                   Console.WriteLine("   ...is SequentialLayout");
                   break;
               case TypeAttributes.ExplicitLayout:
                   Console.WriteLine("   ...is ExplicitLayout");
                   break;
           }

           // Use the class semantics mask to test for class semantics attributes.
           TypeAttributes classSemantics = attr & TypeAttributes.ClassSemanticsMask;
           switch (classSemantics)
           {
               case TypeAttributes.Class:
                   if (t.IsValueType)
                   {
                       Console.WriteLine("   ...is a value type");
                   }
                   else
                   {
                       Console.WriteLine("   ...is a class");
                   }
                   break;
               case TypeAttributes.Interface:
                   Console.WriteLine("   ...is an interface");
                   break;
           }

           if ((attr & TypeAttributes.Abstract) != 0)
           {
               Console.WriteLine("   ...is abstract");
           }

           if ((attr & TypeAttributes.Sealed) != 0)
           {
               Console.WriteLine("   ...is sealed");
           }
           
           Console.WriteLine();
       }
    }
}
// The example displays the following output:
// Attributes for type Example:
//    ...is public
//    ...is AutoLayout
//    ...is a class
//    ...is abstract

// Attributes for type NestedClass:
//    ...is nested and protected
//    ...is AutoLayout
//    ...is a class
//    ...is sealed

// Attributes for type INested:
//    ...is nested and public
//    ...is AutoLayout
//    ...is an interface
//    ...is abstract

// Attributes for type S:
//    ...is not public
//    ...is SequentialLayout
//    ...is a value type
//    ...is sealed
Imports System.Reflection

Friend Structure S
    Public X As Integer
End Structure

Public MustInherit Class Example
    Protected NotInheritable Class NestedClass
    End Class

    Public Interface INested
    End Interface

    Public Shared Sub Main()
        ' Create an array of types.
        Dim types() As Type = { GetType(Example), GetType(NestedClass),
                                GetType(INested), GetType(S) }

        For Each t In types
           Console.WriteLine("Attributes for type {0}:", t.Name)

           Dim attr As TypeAttributes = t.Attributes

           ' Use the visibility mask to test for visibility attributes.
           Dim visibility As TypeAttributes = attr And TypeAttributes.VisibilityMask
           Select Case visibility
               Case TypeAttributes.NotPublic:
                   Console.WriteLine("   ...is not Public")
               Case TypeAttributes.Public:
                   Console.WriteLine("   ...is Public")
               Case TypeAttributes.NestedPublic:
                   Console.WriteLine("   ...is nested and Public")
               Case TypeAttributes.NestedPrivate:
                   Console.WriteLine("   ...is nested and Private")
               Case TypeAttributes.NestedFamANDAssem:
                   Console.WriteLine("   ...is nested, and inheritable only within the assembly" & _
                      vbLf & "         (cannot be declared in Visual Basic)")
               Case TypeAttributes.NestedAssembly:
                   Console.WriteLine("   ...is nested and Friend")
               Case TypeAttributes.NestedFamily:
                   Console.WriteLine("   ...is nested and Protected")
               Case TypeAttributes.NestedFamORAssem:
                   Console.WriteLine("   ...is nested and Protected Friend")
           End Select

           ' Use the layout mask to test for layout attributes.
           Dim layout As TypeAttributes = attr And TypeAttributes.LayoutMask
           Select Case layout
               Case TypeAttributes.AutoLayout:
                   Console.WriteLine("   ...is AutoLayout")
               Case TypeAttributes.SequentialLayout:
                   Console.WriteLine("   ...is SequentialLayout")
               Case TypeAttributes.ExplicitLayout:
                   Console.WriteLine("   ...is ExplicitLayout")
           End Select

           ' Use the class semantics mask to test for class semantics attributes.
           Dim classSemantics As TypeAttributes = attr And TypeAttributes.ClassSemanticsMask
           Select Case classSemantics
               Case TypeAttributes.Class:
                   If t.IsValueType Then
                       Console.WriteLine("   ...is a value type")
                   Else
                       Console.WriteLine("   ...is a class")
                   End If
               Case TypeAttributes.Interface:
                   Console.WriteLine("   ...is an interface")
           End Select

           If 0 <> (attr And TypeAttributes.Abstract) Then _
               Console.WriteLine("   ...is MustInherit")

           If 0 <> (attr And TypeAttributes.Sealed) Then _
               Console.WriteLine("   ...is NotInheritable")
           Console.WriteLine()
       Next
    End Sub
End Class
' The example displays the following output:
'       Attributes for type Example:
'          ...is Public
'          ...is AutoLayout
'          ...is a class
'          ...is MustInherit
'
'       Attributes for type NestedClass:
'          ...is nested and Protected
'          ...is AutoLayout
'          ...is a class
'          ...is NotInheritable
'
'       Attributes for type INested:
'          ...is nested and Public
'          ...is AutoLayout
'          ...is an interface
'          ...is MustInherit
'
'       Attributes for type S:
'          ...is not Public
'          ...is SequentialLayout
'          ...is a value type
'          ...is NotInheritable

설명

열거형의 TypeAttributes 일부 멤버는 상호 배타적인 특성 집합을 나타내는 마스크입니다. 예를 들어 멤버에는 VisibilityMask , , Public``NestedPublic, NestedAssembly``NestedPrivate``NestedFamily``NestedFamANDAssem, 및 NestedFamORAssem 멤버가 포함NotPublic됩니다. 각 특성 집합에는 기본 값이 0인 멤버가 포함되어 있으므로 먼저 And 속성에서 Type.Attributes검색된 특정 System.Reflection.TypeAttributes 값이 있는 마스크 값을 지정해야 합니다. 다음 표에는 마스크 및 해당 마스크에 포함된 개별 멤버가 나열되어 있습니다.

Mask Includes
VisibilityMask NotPublic
공용
NestedPublic
NestedPrivate
NestedFamily
NestedAssembly
NestedFamANDAssem
NestedFamORAssem
LayoutMask 레이아웃
SequentialLayout
ExplicitLayout
ClassSemanticsMask 클래스
인터페이스
StringFormatMask AnsiClass
UnicodeClass
AutoClass
CustomFormatClass
CustomFormatMask 멤버가 없습니다.

이 열거자 클래스의 멤버는 corhdr.h 파일에 정의된 CorTypeAttr 열거자와 일치합니다.

적용 대상