FieldInfo.GetFieldFromHandle Method (RuntimeFieldHandle)
.NET Framework 4
Gets a FieldInfo for the field represented by the specified handle.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- handle
- Type: System.RuntimeFieldHandle
A RuntimeFieldHandle structure that contains the handle to the internal metadata representation of a field.
Return Value
Type: System.Reflection.FieldInfoA FieldInfo object representing the field specified by handle.
| Exception | Condition |
|---|---|
| ArgumentException |
handle is invalid. |
The following code 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 FieldInfo_GetFieldFromHandle { public string x; public char y; public float a; public int b; public static void Main() { // Get the type of the FieldInfo_GetFieldFromHandle class. Type myType = typeof(FieldInfo_GetFieldFromHandle); // Get the fields of the FieldInfo_GetFieldFromHandle class. FieldInfo [] myFieldInfoArray = myType.GetFields(); Console.WriteLine("\nThe field information of the declared" + " fields x, y, a, and b is:\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. Console.WriteLine("{0}", myFieldInfo); } } }
-
ReflectionPermission
when invoked late-bound through mechanisms such as Type.InvokeMember. Associated enumeration: ReflectionPermissionFlag.MemberAccess.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.