FieldAttributes 列挙体とは? わかりやすく解説

FieldAttributes 列挙体

フィールドの属性を記述するフラグを指定します。

この列挙体には、メンバ値のビットごとの組み合わせを可能にする FlagsAttribute 属性が含まれています。

名前空間: System.Reflection
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<SerializableAttribute> _
<FlagsAttribute> _
<ComVisibleAttribute(True)> _
Public Enumeration FieldAttributes
Dim instance As FieldAttributes
[SerializableAttribute] 
[FlagsAttribute] 
[ComVisibleAttribute(true)] 
public enum FieldAttributes
[SerializableAttribute] 
[FlagsAttribute] 
[ComVisibleAttribute(true)] 
public enum class FieldAttributes
/** @attribute SerializableAttribute() */ 
/** @attribute FlagsAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public enum FieldAttributes
SerializableAttribute 
FlagsAttribute 
ComVisibleAttribute(true) 
public enum FieldAttributes
メンバメンバ
 メンバ名説明
.NET Compact Framework によるサポートAssemblyアセンブリ全体からフィールドにアクセスできることを指定します。 
.NET Compact Framework によるサポートFamANDAssemこのアセンブリのサブタイプだけがフィールドにアクセスできることを指定します。 
.NET Compact Framework によるサポートFamily型およびサブタイプだけがフィールドにアクセスできることを指定します。 
.NET Compact Framework によるサポートFamORAssemあらゆる場所にあるサブタイプ、およびアセンブリ全体からフィールドにアクセスできることを指定します。 
.NET Compact Framework によるサポートFieldAccessMask指定されているフィールドのアクセス レベルを指定します。 
.NET Compact Framework によるサポートHasDefaultフィールドが既定値を持つことを指定します。 
.NET Compact Framework によるサポートHasFieldMarshalフィールドがマーシャリング情報を持つことを指定します。 
.NET Compact Framework によるサポートHasFieldRVAフィールドが Relative Virtual Address (RVA) を持つことを指定します。RVA は、現在のイメージ内のメソッド本体の場所を、メソッドが存在するイメージ ファイルの先頭からの相対アドレスで表した値です。 
.NET Compact Framework によるサポートInitOnlyフィールドは初期化されるだけで、初期化後のフィールドに書き込むことができないことを指定します。 
.NET Compact Framework によるサポートLiteralフィールドの値がコンパイル時 (静的バインディングまたは事前バインディング) 定数であることを指定します。set アクセサはありません。 
.NET Compact Framework によるサポートNotSerialized型をリモート処理するときに、フィールドをシリアル化する必要がないことを指定します。 
.NET Compact Framework によるサポートPinvokeImpl今後使用するために予約されています。 
.NET Compact Framework によるサポートPrivate親の型だけがフィールドにアクセスできることを指定します。 
.NET Compact Framework によるサポートPrivateScopeフィールドを参照できないことを指定します。 
.NET Compact Framework によるサポートPublicこのスコープが可視である任意のメンバがフィールドにアクセスできることを指定します。 
.NET Compact Framework によるサポートReservedMask予約済み。 
.NET Compact Framework によるサポートRTSpecialName共通言語ランタイム (メタデータ内部 API) が名前のエンコードをチェックする必要があることを指定します。 
.NET Compact Framework によるサポートSpecialName特別なメソッドを指定します。メソッドが特別である理由は名前で説明します。 
.NET Compact Framework によるサポートStaticフィールドが定義済みの型を表すことを指定します。それ以外の場合は、フィールドが表す型はインスタンスごとに異なります。 
解説解説

FieldAttributes は、FieldAccessMask からの値を使用して、属性値のアクセス可能な部分だけマスクをオフにします。たとえば、次のコードは Attributes のパブリック ビットが設定されているかどうかを判断します。

If (Attributes And FieldAttributes.FieldAccessMask)
 = _
    FieldAttributes.Public Then
if ((Attributes & FieldAttributes.FieldAccessMask) == 
    FieldAttributes.Public)

FieldAttributes を取得するには、最初に Type クラスを取得します。そして、その Type から FieldInfo を取得します。そして、その FieldInfo から Attributes を取得します。

列挙値は、フィールドに実装されている属性をビットごとの OR 演算によって組み合わせて表す数値です。

使用例使用例

この例では、3 つのフィールドが構築され、FieldAttributes 値が表示されます。FieldAttributes 値には、3 番目のフィールドで示すように、Public と Literal の両方など、複数の属性を含めることができます。

Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic

Public Class Demo
    ' Declare three fields.
    ' The first field is private.
    Private m_field As String
 = "String A"

    'The second field is public.
    Public Field As String
 = "String B"

    ' The third field is public and const, hence also static
    ' and literal with a default value.
    Public Const FieldC As
 String = "String C"

End Class

Module Module1
    Sub Main()
        ' Create an instance of the Demo class.
        Dim d As New Demo()

        Console.WriteLine(vbCrLf & "Reflection.FieldAttributes")

        ' Get a Type object for Demo, and a FieldInfo for each of
        ' the three fields. Use the FieldInfo to display field
        ' name, value for the Demo object in d, and attributes.
        '
        Dim myType As Type = GetType(Demo)

        Dim fiPrivate As FieldInfo = myType.GetField("m_field",
 _
            BindingFlags.NonPublic Or BindingFlags.Instance)
        DisplayField(d, fiPrivate)

        Dim fiPublic As FieldInfo = myType.GetField("Field",
 _
            BindingFlags.Public Or BindingFlags.Instance)
        DisplayField(d, fiPublic)

        Dim fiConstant As FieldInfo = myType.GetField("FieldC",
 _
            BindingFlags.Public Or BindingFlags.Static)
        DisplayField(d, fiConstant)
    End Sub

    Sub DisplayField(ByVal obj As
 Object, ByVal f As FieldInfo)

        ' Display the field name, value, and attributes.
        '
        Console.WriteLine("{0} = ""{1}"";
 attributes: {2}", _
            f.Name, f.GetValue(obj), f.Attributes)
    End Sub

End Module

' This code example produces the following output:
'
'm_field = "String A"; attributes: Private
'Field = "String B"; attributes: Public
'FieldC = "String C"; attributes: Public, Static, Literal,
 HasDefault
using System;
using System.Reflection;

public class Demo
{
    // Make three fields:
    // The first field is private.
    private string m_field = "String A";

    // The second field is public.
    public string Field = "String B";

    // The third field is public const (hence also literal and static)
,
    // with a default value.
    public const string
 FieldC = "String C";
}

public class Myfieldattributes
{
    public static void Main()
    {
        Console.WriteLine ("\nReflection.FieldAttributes");
        Demo d = new Demo();
 
        // Get a Type object for Demo, and a FieldInfo for each of
        // the three fields. Use the FieldInfo to display field
        // name, value for the Demo object in d, and attributes.
        //
        Type myType = typeof(Demo);
        FieldInfo fiPrivate = myType.GetField("m_field",
            BindingFlags.NonPublic | BindingFlags.Instance);
        DisplayField(d, fiPrivate);

        FieldInfo fiPublic = myType.GetField("Field",
            BindingFlags.Public | BindingFlags.Instance);
        DisplayField(d, fiPublic);

        FieldInfo fiConstant = myType.GetField("FieldC",
            BindingFlags.Public | BindingFlags.Static);
        DisplayField(d, fiConstant);
    }

    static void DisplayField(Object obj, FieldInfo
 f)
    { 
        // Display the field name, value, and attributes.
        //
        Console.WriteLine("{0} = \"{1}\"; attributes: {2}", 
            f.Name, f.GetValue(obj), f.Attributes);
    }
}

/* This code example produces the following output:

Reflection.FieldAttributes
m_field = "String A"; attributes: Private
Field = "String B"; attributes: Public
FieldC = "String C"; attributes: Public, Static, Literal, HasDefault
 */
using namespace System;
using namespace System::Reflection;
using namespace System::Security::Permissions;

public ref class Demo
{
private:
    // Make three fields:
    // The first field is private.
    String^ m_field;

    // The second field is public.
public:
    String^ Field;

    // The third field is public and literal. 
    literal String^ FieldC = "String C";

    Demo() { m_field = "String A"; Field = "String B"; }
};

static void DisplayField(Object^ obj, FieldInfo^
 f)
{ 
    // Display the field name, value, and attributes.
    //
    Console::WriteLine("{0} = \"{1}\"; attributes: {2}", 
        f->Name, f->GetValue(obj), f->Attributes);
};

void main()
{
    Console::WriteLine ("\nReflection.FieldAttributes");
    Demo^ d = gcnew Demo();

    // Get a Type object for Demo, and a FieldInfo for each of
    // the three fields. Use the FieldInfo to display field
    // name, value for the Demo object in d, and attributes.
    //
    Type^ myType = Demo::typeid;

    FieldInfo^ fiPrivate = myType->GetField("m_field",
        BindingFlags::NonPublic | BindingFlags::Instance);
    DisplayField(d, fiPrivate);

    FieldInfo^ fiPublic = myType->GetField("Field",
        BindingFlags::Public | BindingFlags::Instance);
    DisplayField(d, fiPublic);

    FieldInfo^ fiConstant = myType->GetField("FieldC",
        BindingFlags::Public | BindingFlags::Static);
    DisplayField(d, fiConstant);
}

/* This code example produces the following output:

Reflection.FieldAttributes
m_field = "String A"; attributes: Private
Field = "String B"; attributes: Public
FieldC = "String C"; attributes: Public, Static, Literal, HasDefault
 */
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「FieldAttributes 列挙体」の関連用語

FieldAttributes 列挙体のお隣キーワード

   

英語⇒日本語
日本語⇒英語
   



FieldAttributes 列挙体のページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS