Freigeben über


FieldInfo.MemberType-Eigenschaft

Ruft einen MemberTypes-Wert ab, der angibt, dass dieser Member ein Feld ist.

Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Overrides ReadOnly Property MemberType As MemberTypes
'Usage
Dim instance As FieldInfo
Dim value As MemberTypes

value = instance.MemberType
public override MemberTypes MemberType { get; }
public:
virtual property MemberTypes MemberType {
    MemberTypes get () override;
}
/** @property */
public MemberTypes get_MemberType ()
public override function get MemberType () : MemberTypes

Eigenschaftenwert

Ein MemberTypes-Wert, der angibt, dass dieser Member ein Feld ist.

Hinweise

Diese Eigenschaft überschreibt MemberType. Wenn Sie daher eine Gruppe von MemberInfo-Objekten untersuchen, z. B. das von GetMembers zurückgegebene Array, gibt die MemberType-Eigenschaft nur dann MemberTypes.Field zurück, wenn ein bestimmter Member ein Feld ist.

Beispiel

Im folgenden Beispiel wird bestimmt, ob der angegebene Member ein Feld ist, und das Ergebnis wird angezeigt.

Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic

' 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
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;
    }
}
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;
}
import System.*;
import System.Reflection.*;

// Make a field.
public class MyField
{
    private String field = "a private field";

    /** @property 
     */
    public String get_Field()
    {
        return field;
    } //get_Field
} //MyField

public class MyFieldInfo
{
    public static void main(String[] args)
    {
        Console.WriteLine("\nReflection.FieldInfo");
        MyField myField = new MyField();

        // Get the Type and FieldInfo.
        Type myType = Type.GetType("MyField");
        FieldInfo myFieldInfo = myType.GetField("field", 
            BindingFlags.NonPublic | BindingFlags.Instance);

        // Get and display the MemberType.
        Console.Write("\n{0}.", myType.get_FullName());
        Console.Write("{0} - ", myFieldInfo.get_Name());
        Console.Write("{0};", myField.get_Field());
        MemberTypes myMemberTypes = myFieldInfo.get_MemberType();
        Console.Write("MemberType is a {0}.", myMemberTypes.ToString());
    } //main
} //MyFieldInfo
import System;
import System.Reflection;

//Make a field 
public class Myfield
{
   private var field : String = "a private field";
   public function get Field() : String {
       return field;
   }
}
 
public class Myfieldinfo
{
   public static function Main() : void
   {
      Console.WriteLine ("\nReflection.FieldInfo");
      var myfield : Myfield = new Myfield();
 
      //Get the Type and FieldInfo
      var MyType : Type = Type.GetType("Myfield");
      var Myfieldinfo : FieldInfo = 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);
 
      var Mymembertypes : MemberTypes = Myfieldinfo.MemberType;
      Console.Write(" MemberType is a {0}", Mymembertypes.ToString());
   }
}
Myfieldinfo.Main();

Dieser Code erzeugt die folgende Ausgabe:

Reflection.FieldInfo

Myfield.field - a private field; MemberType is a Field

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

FieldInfo-Klasse
FieldInfo-Member
System.Reflection-Namespace
FieldInfo-Klasse
Type