FieldInfo.GetFieldFromHandle Method (RuntimeFieldHandle)

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";
      }
   }
}


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show: