英語で読む

次の方法で共有


TypeAttributes 列挙型

定義

型属性を指定します。

この列挙体は、メンバー値のビットごとの組み合わせをサポートしています。

C#
[System.Flags]
public enum TypeAttributes
C#
[System.Flags]
[System.Serializable]
public enum TypeAttributes
C#
[System.Flags]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
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 のスローを含め、実装に固有の手段で解釈されます。 .NET FrameworkのMicrosoft実装では使用されません。

CustomFormatMask 12582912

標準以外のエンコーディング情報を取得し、ネイティブな相互運用性を実現するために使用されます。 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

クラスをシリアル化できることを指定します。

SpecialName 1024

名前で説明するという方法で、クラスが特別であることを指定します。

StringFormatMask 196608

ネイティブな相互運用性を得るための文字列情報の取得に使用されます。

UnicodeClass 65536

LPTSTR は UNICODE として解釈されます。

VisibilityMask 7

型の参照可能範囲情報を指定します。

WindowsRuntime 16384

Windows ランタイム型を指定します。

次の例では、さまざまな型を Attributes 表すオブジェクトの プロパティ Type の値を取得し、個々の属性フラグが設定されているかどうかを判断します。

C#
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

注釈

列挙体の一部の TypeAttributes メンバーは、相互に排他的な属性のセットを表すマスクです。 たとえば、VisibilityMaskメンバーには、、Public、、NestedPublicNestedPrivateNestedAssemblyNestedFamilyNestedFamANDAssemおよび の各メンバーがNestedFamORAssem含まれます。NotPublic 各属性セットには基になる値が 0 のメンバーが含まれているため、まずAnd、 などのType.Attributesプロパティから取得された特定System.Reflection.TypeAttributesの値を持つマスクの値を指定する必要があります。 次の表に、マスクと、マスクに含まれる個々のメンバーを示します。

マスク Includes
VisibilityMask NotPublic
パブリック
NestedPublic
NestedPrivate
NestedFamily
NestedAssembly
NestedFamANDAssem
NestedFamORAssem
LayoutMask AutoLayout
SequentialLayout
ExplicitLayout
ClassSemanticsMask クラス
インターフェイス
StringFormatMask AnsiClass
UnicodeClass
AutoClass
CustomFormatClass
CustomFormatMask メンバーがありません。

この列挙子クラスのメンバーは、corhdr.h ファイルで定義されている CorTypeAttr 列挙子と一致します。

適用対象

製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0