다음을 통해 공유


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
특성

필드

Name Description
AnsiClass 0

LPTSTR은 ANSI로 해석됩니다.

AutoLayout 0

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

Class 0

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

NotPublic 0

클래스가 public이 아님을 지정합니다.

Public 1

클래스가 public임을 지정합니다.

NestedPublic 2

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

NestedPrivate 3

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

NestedFamily 4

클래스가 패밀리 표시 유형과 함께 중첩되므로 자체 형식 및 파생 형식 내의 메서드에서만 액세스할 수 있도록 지정합니다.

NestedAssembly 5

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

NestedFamANDAssem 6

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

NestedFamORAssem 7

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

VisibilityMask 7

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

SequentialLayout 8

필드가 메타데이터로 내보내진 순서대로 클래스 필드가 순차적으로 배치되도록 지정합니다.

ExplicitLayout 16

지정된 오프셋에 클래스 필드가 배치되도록 지정합니다.

ExtendedLayout 24
LayoutMask 24

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

ClassSemanticsMask 32

클래스 의미 체계 정보를 지정합니다. 현재 클래스는 컨텍스트(다른 민첩)입니다.

Interface 32

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

Abstract 128

형식이 추상 형식임을 지정합니다.

Sealed 256

클래스가 구체적이며 확장할 수 없음을 지정합니다.

SpecialName 1024

클래스가 이름으로 표시되는 방식으로 특수하게 지정합니다.

RTSpecialName 2048

런타임은 이름 인코딩을 확인해야 합니다.

Import 4096

클래스 또는 인터페이스를 다른 모듈에서 가져오게 지정합니다.

Serializable 8192

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

WindowsRuntime 16384

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

UnicodeClass 65536

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

AutoClass 131072

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

CustomFormatClass 196608

LPSTR은 몇 가지 구현별 수단으로 해석되며, 여기에는 을 throw할 NotSupportedException가능성이 포함됩니다. .NET Framework의 Microsoft 구현에는 사용되지 않습니다.

StringFormatMask 196608

네이티브 상호 운용성을 위한 문자열 정보를 검색하는 데 사용됩니다.

HasSecurity 262144

형식에는 보안 연결이 있습니다.

ReservedMask 264192

런타임 사용을 위해 예약된 특성입니다.

BeforeFieldInit 1048576

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

CustomFormatMask 12582912

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

예제

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

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 , , NestedPublicPublic, NestedPrivate, NestedAssemblyNestedFamilyNestedFamANDAssemNestedFamORAssem 멤버가 포함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 열거자와 일치합니다.

적용 대상