Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Ruft ein RuntimeFieldHandle ab, das das Handle für die interne Metadatendarstellung eines Felds darstellt.
Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public MustOverride ReadOnly Property FieldHandle As RuntimeFieldHandle
'Usage
Dim instance As FieldInfo
Dim value As RuntimeFieldHandle
value = instance.FieldHandle
public abstract RuntimeFieldHandle FieldHandle { get; }
public:
virtual property RuntimeFieldHandle FieldHandle {
RuntimeFieldHandle get () abstract;
}
/** @property */
public abstract RuntimeFieldHandle get_FieldHandle ()
public abstract function get FieldHandle () : RuntimeFieldHandle
Eigenschaftenwert
Ein Handle für die interne Metadatendarstellung eines Felds.
Hinweise
Die Handles sind nur in der Anwendungsdomäne gültig, in der sie angefordert wurden.
Beispiel
Im folgenden Beispiel werden die Feldinformationen aus MyClass.MyField abgerufen, und es wird das Feld angezeigt, das dem Feldhandle zugeordnet ist.
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
Public Class [MyClass]
Public MyField As String = "Microsoft"
End Class '[MyClass]
Public Class FieldInfo_FieldHandle
Public Shared Sub Main()
Dim [myClass] As New [MyClass]()
' Get the type of MyClass.
Dim myType As Type = GetType([MyClass])
Try
' Get the field information of MyField.
Dim myFieldInfo As FieldInfo = myType.GetField("MyField", BindingFlags.Public Or BindingFlags.Instance)
' Determine whether or not the FieldInfo object is null.
If Not (myFieldInfo Is Nothing) Then
' Get the handle for the field.
Dim myFieldHandle As RuntimeFieldHandle = myFieldInfo.FieldHandle
DisplayFieldHandle(myFieldHandle)
Else
Console.WriteLine("The myFieldInfo object is null.")
End If
Catch e As Exception
Console.WriteLine(" Exception: {0}", e.Message.ToString())
End Try
End Sub 'Main
Public Shared Sub DisplayFieldHandle(ByVal myFieldHandle As RuntimeFieldHandle)
' Get the type from the handle.
Dim myField As FieldInfo = FieldInfo.GetFieldFromHandle(myFieldHandle)
' Display the type.
Console.WriteLine(ControlChars.Cr + "Displaying the field from the handle." + ControlChars.Cr)
Console.WriteLine("The type is {0}.", myField.ToString())
End Sub 'DisplayFieldHandle
End Class 'FieldInfo_FieldHandle
using System;
using System.Reflection;
public class MyClass
{
public string MyField = "Microsoft";
}
public class FieldInfo_FieldHandle
{
public static void Main()
{
MyClass myClass =new MyClass();
// Get the type of MyClass.
Type myType = typeof(MyClass);
try
{
// Get the field information of MyField.
FieldInfo myFieldInfo = myType.GetField("MyField", BindingFlags.Public
| BindingFlags.Instance);
// Determine whether or not the FieldInfo object is null.
if(myFieldInfo!=null)
{
// Get the handle for the field.
RuntimeFieldHandle myFieldHandle=myFieldInfo.FieldHandle;
DisplayFieldHandle(myFieldHandle);
}
else
{
Console.WriteLine("The myFieldInfo object is null.");
}
}
catch(Exception e)
{
Console.WriteLine("Exception: {0}", e.Message);
}
}
public static void DisplayFieldHandle(RuntimeFieldHandle myFieldHandle)
{
// Get the type from the handle.
FieldInfo myField = FieldInfo.GetFieldFromHandle(myFieldHandle);
// Display the type.
Console.WriteLine("\nDisplaying the field from the handle.\n");
Console.WriteLine("The type is {0}.", myField.ToString());
}
}
using namespace System;
using namespace System::Reflection;
public ref class MyClass
{
public:
String^ MyField;
};
void DisplayFieldHandle( RuntimeFieldHandle myFieldHandle )
{
// Get the type from the handle.
FieldInfo^ myField = FieldInfo::GetFieldFromHandle( myFieldHandle );
// Display the type.
Console::WriteLine( "\nDisplaying the field from the handle.\n" );
Console::WriteLine( "The type is {0}.", myField );
}
int main()
{
MyClass^ myClass = gcnew MyClass;
// Get the type of MyClass.
Type^ myType = MyClass::typeid;
try
{
// Get the field information of MyField.
FieldInfo^ myFieldInfo = myType->GetField( "MyField", static_cast<BindingFlags>(BindingFlags::Public | BindingFlags::Instance) );
// Determine whether or not the FieldInfo Object* is 0.
if ( myFieldInfo != nullptr )
{
// Get the handle for the field.
RuntimeFieldHandle myFieldHandle = myFieldInfo->FieldHandle;
DisplayFieldHandle( myFieldHandle );
}
else
{
Console::WriteLine( "The myFieldInfo Object* is 0." );
}
}
catch ( Exception^ e )
{
Console::WriteLine( "Exception: {0}", e->Message );
}
}
import System.*;
import System.Reflection.*;
public class MyClass
{
public String myField = "Microsoft";
} //MyClass
public class FieldInfoFieldHandle
{
public static void main(String[] args)
{
MyClass myClass = new MyClass();
// Get the type of MyClass.
Type myType = MyClass.class.ToType();
try {
// Get the field information of myField.
FieldInfo myFieldInfo = myType.GetField("myField",
BindingFlags.Public | BindingFlags.Instance);
// Determine whether or not the FieldInfo object is null.
if (myFieldInfo != null) {
// Get the handle for the field.
RuntimeFieldHandle myFieldHandle = myFieldInfo.
get_FieldHandle();
DisplayFieldHandle(myFieldHandle);
}
else {
Console.WriteLine("The myFieldInfo object is null.");
}
}
catch (System.Exception e) {
Console.WriteLine("Exception: {0}", e.get_Message());
}
} //main
public static void DisplayFieldHandle(RuntimeFieldHandle myFieldHandle)
{
// Get the type from the handle.
FieldInfo myField = FieldInfo.GetFieldFromHandle(myFieldHandle);
// Display the type.
Console.WriteLine("\nDisplaying the field from the handle.\n");
Console.WriteLine("The type is {0}.", myField.ToString());
} //DisplayFieldHandle
} //FieldInfoFieldHandle
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