FieldAttributes FieldAttributes FieldAttributes FieldAttributes Enum

定義

フィールドの属性を記述するフラグを指定します。Specifies flags that describe the attributes of a field.

この列挙型には FlagsAttribute 属性があり、メンバー値ではビットごとの組み合わせを使用できます。

public enum class FieldAttributes
[System.Flags]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public enum FieldAttributes
type FieldAttributes = 
Public Enum FieldAttributes
継承
FieldAttributesFieldAttributesFieldAttributesFieldAttributes
属性

フィールド

Assembly Assembly Assembly Assembly 3

アセンブリ全体からフィールドにアクセスできることを指定します。Specifies that the field is accessible throughout the assembly.

FamANDAssem FamANDAssem FamANDAssem FamANDAssem 2

このアセンブリのサブタイプだけがフィールドにアクセスできることを指定します。Specifies that the field is accessible only by subtypes in this assembly.

Family Family Family Family 4

型およびサブタイプだけがフィールドにアクセスできることを指定します。Specifies that the field is accessible only by type and subtypes.

FamORAssem FamORAssem FamORAssem FamORAssem 5

あらゆる場所にあるサブタイプ、およびアセンブリ全体からフィールドにアクセスできることを指定します。Specifies that the field is accessible by subtypes anywhere, as well as throughout this assembly.

FieldAccessMask FieldAccessMask FieldAccessMask FieldAccessMask 7

指定されているフィールドのアクセス レベルを指定します。Specifies the access level of a given field.

HasDefault HasDefault HasDefault HasDefault 32768

フィールドが既定値を持つことを指定します。Specifies that the field has a default value.

HasFieldMarshal HasFieldMarshal HasFieldMarshal HasFieldMarshal 4096

フィールドがマーシャリング情報を持つことを指定します。Specifies that the field has marshaling information.

HasFieldRVA HasFieldRVA HasFieldRVA HasFieldRVA 256

フィールドが RVA (Relative Virtual Address) を持つことを指定します。Specifies that the field has a relative virtual address (RVA). RVA は、現在のイメージ内のメソッド本体の場所を、メソッドが存在するイメージ ファイルの先頭からの相対アドレスで表した値です。The RVA is the location of the method body in the current image, as an address relative to the start of the image file in which it is located.

InitOnly InitOnly InitOnly InitOnly 32

フィールドについて、初期化のみを行い、コンストラクターの本体でしか設定できないように指定します。Specifies that the field is initialized only, and can be set only in the body of a constructor.

Literal Literal Literal Literal 64

フィールドの値がコンパイル時 (静的バインディングまたは事前バインディング) 定数であることを指定します。Specifies that the field's value is a compile-time (static or early bound) constant. 設定しようとすると、FieldAccessException がスローされます。Any attempt to set it throws a FieldAccessException.

NotSerialized NotSerialized NotSerialized NotSerialized 128

型をリモート処理するときに、フィールドをシリアル化する必要がないことを指定します。Specifies that the field does not have to be serialized when the type is remoted.

PinvokeImpl PinvokeImpl PinvokeImpl PinvokeImpl 8192

将来使用するために予約されています。Reserved for future use.

Private Private Private Private 1

親の型だけがフィールドにアクセスできることを指定します。Specifies that the field is accessible only by the parent type.

PrivateScope PrivateScope PrivateScope PrivateScope 0

フィールドを参照できないことを指定します。Specifies that the field cannot be referenced.

Public Public Public Public 6

このスコープが可視である任意のメンバーがフィールドにアクセスできることを指定します。Specifies that the field is accessible by any member for whom this scope is visible.

ReservedMask ReservedMask ReservedMask ReservedMask 38144

予約済み。Reserved.

RTSpecialName RTSpecialName RTSpecialName RTSpecialName 1024

共通言語ランタイム (メタデータ内部 API) が名前のエンコードをチェックする必要があることを指定します。Specifies that the common language runtime (metadata internal APIs) should check the name encoding.

SpecialName SpecialName SpecialName SpecialName 512

特別なメソッドを指定します。メソッドが特別である理由は名前で説明します。Specifies a special method, with the name describing how the method is special.

Static Static Static Static 16

フィールドが定義済みの型を表すことを指定します。それ以外の場合は、フィールドが表す型はインスタンスごとに異なります。Specifies that the field represents the defined type, or else it is per-instance.

この例では、3 つのフィールドが構築された、FieldAttributes値が表示されます。In this example, three fields are built and the FieldAttributes values are displayed. AFieldAttributes値が 1 つ以上の属性があり、たとえば、両方を含めることができますPublicLiteral3 番目のフィールドのように、します。A FieldAttributes value can contain more than one attribute, for example, both Public and Literal, as shown in the third field.

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
 */
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
 */
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

注釈

FieldAttributes 値を使用してFieldAccessMaskマスクのユーザー補助機能に関連する属性の値の部分のみオフにします。FieldAttributes uses the value from FieldAccessMask to mask off only the parts of the attribute value that pertain to the accessibility. 場合、たとえば、次のコードが決定Attributesビットがパブリックに設定します。For example, the following code determines if Attributes has the public bit set.

FieldInfo^ fi = obj->GetType()->GetField("field1");

if ((fi->Attributes & FieldAttributes::FieldAccessMask) ==
    FieldAttributes::Public)
{
    Console::WriteLine("{0:s} is public. Value: {1:d}", fi->Name, fi->GetValue(obj));
}
FieldInfo fi = obj.GetType().GetField("field1");

if ((fi.Attributes & FieldAttributes.FieldAccessMask) ==
    FieldAttributes.Public)
{
    Console.WriteLine("{0:s} is public. Value: {1:d}", fi.Name, fi.GetValue(obj));
}
Dim fi As FieldInfo = obj.GetType().GetField("field1")

If (fi.Attributes And FieldAttributes.FieldAccessMask) = _
    FieldAttributes.Public Then
    Console.WriteLine("{0:s} is public. Value: {1:d}", fi.Name, fi.GetValue(obj))
End If

取得する、 FieldAttributes、クラスをまず取得Typeします。To get the FieldAttributes, first get the class Type. Type、取得、FieldInfoします。From the Type, get the FieldInfo. FieldInfo、取得、Attributesします。From the FieldInfo, get the Attributes.

列挙値は、フィールドに実装されている属性のビットごとの OR を表す数値です。The enumerated value is a number representing the bitwise OR of the attributes implemented on the field.

適用対象