FieldInfo.MemberType 속성

정의

이 멤버가 필드임을 나타내는 MemberTypes 값을 가져옵니다.Gets a MemberTypes value indicating that this member is a field.

public:
 virtual property System::Reflection::MemberTypes MemberType { System::Reflection::MemberTypes get(); };
public override System.Reflection.MemberTypes MemberType { get; }
member this.MemberType : System.Reflection.MemberTypes
Public Overrides ReadOnly Property MemberType As MemberTypes

속성 값

이 멤버가 필드임을 나타내는 MemberTypes 값입니다.A MemberTypes value indicating that this member is a field.

구현

예제

다음 예제에서는 지정된 된 멤버는 필드와 결과 표시 하는지 여부를 결정 합니다.The following example determines whether the specified member is a field and displays the result.

using namespace System;
using namespace System::Reflection;

// Make a field.
public ref class Myfield
{
private:
   String^ field;

public:
   Myfield()
      : field( "a private field" )
   {}


   property String^ Field 
   {
      String^ get()
      {
         return field;
      }

   }

};

int main()
{
   Console::WriteLine( "\nReflection.FieldInfo" );
   Myfield^ myfield = gcnew Myfield;
   
   // Get the Type and FieldInfo.
   Type^ MyType = Type::GetType( "Myfield" );
   FieldInfo^ Myfieldinfo = MyType->GetField( "field", static_cast<BindingFlags>(BindingFlags::NonPublic | BindingFlags::Instance) );
   
   // Get and display the MemberType.
   Console::Write( "\n{0}.", MyType->FullName );
   Console::Write( "{0} - ", Myfieldinfo->Name );
   Console::Write( "{0};", myfield->Field );
   MemberTypes Mymembertypes = Myfieldinfo->MemberType;
   Console::Write( "MemberType is a {0}.", Mymembertypes );
   return 0;
}

using System;
using System.Reflection;
 
// Make a field.
public class Myfield
{
    private string field = "a private field";
    public string Field
    {
        get{return field;}
    }
}
  
public class Myfieldinfo
{
    public static int Main()
    {
        Console.WriteLine ("\nReflection.FieldInfo");
        Myfield Myfield = new Myfield();
  
        // Get the Type and FieldInfo.
        Type MyType = typeof(Myfield);
        FieldInfo Myfieldinfo = MyType.GetField("field", BindingFlags.NonPublic|BindingFlags.Instance);
  
        // Get and display the MemberType.
        Console.Write ("\n{0}.", MyType.FullName);
        Console.Write ("{0} - ", Myfieldinfo.Name);
        Console.Write ("{0};", Myfield.Field);
        MemberTypes Mymembertypes = Myfieldinfo.MemberType;
        Console.Write("MemberType is a {0}.", Mymembertypes.ToString());
        return 0;
    }
}
Imports System.Reflection

' Make a field.
Public Class Myfield
    Private m_field As String = "a private field"

    Public ReadOnly Property Field() As String
        Get
            Return m_field
        End Get
    End Property
End Class

Public Class Myfieldinfo

    Public Shared Sub Main()
        Console.WriteLine()
        Console.WriteLine(ControlChars.Cr & "Reflection.FieldInfo")
        Console.WriteLine()
        Dim Myfield As New Myfield()

        ' Get the Type and FieldInfo.
        Dim MyType As Type = GetType(Myfield)
        Dim Myfieldinfo As FieldInfo = _
           MyType.GetField("m_field", BindingFlags.NonPublic Or BindingFlags.Instance)

        ' Get and display the MemberType.
        Console.Write(ControlChars.Cr & "{0}.", MyType.FullName)
        Console.Write("{0} - ", Myfieldinfo.Name)
        Console.Write("{0};", Myfield.Field)
        Dim Mymembertypes As MemberTypes = Myfieldinfo.MemberType
        Console.Write("MemberType is a {0}.", Mymembertypes.ToString())
    End Sub
End Class

이 코드의 결과는 다음과 같습니다.This code produces the following output:

Reflection.FieldInfoReflection.FieldInfo

Myfield.field-전용 필드입니다. MemberType 필드입니다.Myfield.field - a private field; MemberType is a Field

설명

이 속성은 MemberType를 재정의 합니다.This property overrides MemberType. 따라서 MemberInfo 개체 집합 (예: GetMembers에서 반환 된 배열)을 검사할 때 MemberType 속성은 지정 된 멤버가 필드인 경우에만 MemberTypes.Field을 반환 합니다.Therefore, when you examine a set of MemberInfo objects - for example, the array returned by GetMembers - the MemberType property returns MemberTypes.Field only when a given member is a field.

적용 대상

추가 정보