FieldInfo.FieldHandle Property
.NET Framework 4.5
Gets a RuntimeFieldHandle, which is a handle to the internal metadata representation of a field.
Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)
Property Value
Type: System.RuntimeFieldHandleA handle to the internal metadata representation of a field.
Implements
_FieldInfo.FieldHandleThe following example retrieves MyClass.MyField field information and displays the field associated with the field handle.
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()); } }
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.