FieldAttributes 열거형

정의

필드의 특성을 설명하는 플래그를 지정합니다.

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

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

필드

Assembly 3

어셈블리 전체에서 필드에 액세스할 수 있도록 지정합니다.

FamANDAssem 2

이 어셈블리의 하위 형식에서만 필드에 액세스할 수 있도록 지정합니다.

Family 4

형식 및 하위 형식에서만 필드에 액세스할 수 있도록 지정합니다.

FamORAssem 5

이 어셈블리 전체는 물론 모든 위치의 하위 형식에서 필드에 액세스할 수 있도록 지정합니다.

FieldAccessMask 7

지정된 필드의 액세스 수준을 지정합니다.

HasDefault 32768

필드가 기본값을 갖도록 지정합니다.

HasFieldMarshal 4096

필드에 마샬링 정보가 포함되도록 지정합니다.

HasFieldRVA 256

필드에 RVA(상대 가상 주소)가 포함되도록 지정합니다. RVA는 자신이 위치한 이미지 파일의 시작에 상대적인 주소로 현재 이미지에 있는 메서드 본문의 위치입니다.

InitOnly 32

필드가 초기화만 되었으며 생성자 본문에서만 설정할 수 있음을 지정합니다.

Literal 64

필드의 값이 정적 또는 초기 바인딩된 컴파일 타임 상수가 되도록 지정합니다. 설정을 시도하면 FieldAccessException이 throw됩니다.

NotSerialized 128

원격 형식일 때 필드를 serialize하지 않도록 지정합니다.

PinvokeImpl 8192

나중에 사용하기 위해 예약되어 있습니다.

Private 1

부모 형식에서만 필드에 액세스할 수 있도록 지정합니다.

PrivateScope 0

필드를 참조할 수 없도록 지정합니다.

Public 6

이 범위를 볼 수 있는 모든 멤버가 필드에 액세스할 수 있도록 지정합니다.

ReservedMask 38144

예약되어 있습니다.

RTSpecialName 1024

공용 언어 런타임(메타데이터 내부 API)에서 이름 인코딩을 확인하도록 지정합니다.

SpecialName 512

메서드의 특수성을 설명하는 이름을 가진 특수 메서드를 지정합니다.

Static 16

필드가 정의된 형식을 나타내도록 지정합니다. 그렇지 않으면 인스턴스 단위가 됩니다.

예제

이 예제에서는 세 개의 필드가 빌드되고 FieldAttributes 값이 표시됩니다. 값은 FieldAttributes 세 번째 필드에 표시된 것처럼 둘 이상의 특성을 Public Literal포함할 수 있습니다.

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.Reflection

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 사용하여 접근성과 관련된 특성 값의 일부만 마스킹합니다. 예를 들어 다음 코드는 퍼블릭 비트 집합이 있는지 Attributes 여부를 결정합니다.

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를 가져옵니다. 에서 .Type``FieldInfo 에서 .FieldInfo``Attributes

열거형 값은 필드에 구현된 특성의 비트 OR을 나타내는 숫자입니다.

적용 대상