FieldInfo.MemberType 属性


获取 MemberTypes 值,该值指示此成员是字段。Gets a MemberTypes value indicating that this member is a field.

 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
   String^ field;

      : 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
            Return m_field
        End Get
    End Property
End Class

Public Class Myfieldinfo

    Public Shared Sub Main()
        Console.WriteLine(ControlChars.Cr & "Reflection.FieldInfo")
        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:


Myfield-专用字段;MemberType 是一个字段Myfield.field - a private field; MemberType is a Field


此属性将重写 MemberTypeThis property overrides MemberType. 因此,在检查一组 MemberInfo 对象(例如,由 GetMembers 返回的数组)时,MemberType 属性仅在给定成员为字段时才返回 MemberTypes.FieldTherefore, 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.