FieldInfo.GetFieldFromHandle Method (RuntimeFieldHandle)

July 28, 2014

Gets a FieldInfo for the field represented by the specified handle.

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

public static FieldInfo GetFieldFromHandle(
	RuntimeFieldHandle handle
)

Parameters

handle
Type: System.RuntimeFieldHandle
A structure that contains the handle to the internal metadata representation of a field.

Return Value

Type: System.Reflection.FieldInfo
The field that is specified by handle.

ExceptionCondition
ArgumentException

handle is invalid.

MethodAccessException

The member is invoked late-bound through mechanisms such as Type.InvokeMember.

Handles are valid only in the application domain in which they were obtained.

The following example uses the Type.GetFields method to get FieldInfo objects for the fields of a type, gets a RuntimeFieldHandle structure for each field, and then retrieves the FieldInfo objects from the handles using this overload of the GetFieldFromHandle method.


using System;
using System.Reflection;

public class Example
{
   public string x;
   public char y;
   public float a;
   public int b;

   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      // Get the type of the Example class.
      Type myType = typeof(Example);
      // Get the fields of the Example class.
      FieldInfo[] myFieldInfoArray = myType.GetFields();
      outputBlock.Text += "\nThe field information of the declared" +
          " fields x, y, a, and b is:\n" + "\n";
      RuntimeFieldHandle myRuntimeFieldHandle;
      for (int i = 0; i < myFieldInfoArray.Length; i++)
      {
         // Get the RuntimeFieldHandle of myFieldInfoArray.
         myRuntimeFieldHandle = myFieldInfoArray[i].FieldHandle;
         // Call the GetFieldFromHandle method. 
         FieldInfo myFieldInfo = FieldInfo.GetFieldFromHandle(myRuntimeFieldHandle);
         // Display the FieldInfo of myFieldInfo.
         outputBlock.Text += String.Format("{0}", myFieldInfo) + "\n";
      }
   }
}


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft