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
)
public static FieldInfo GetFieldFromHandle (
	RuntimeFieldHandle handle
)
public static function GetFieldFromHandle (
	handle : RuntimeFieldHandle
) : FieldInfo

Parameters

handle

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

Return Value

A FieldInfo object representing the field specified by handle.

Exception typeCondition

ArgumentException

handle is invalid.

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

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

import System.*;
import System.Reflection.*;

public class FieldInfoGetFieldFromHandle
{
    public String x;
    public char y;
    public float a;
    public int b;

    public static void main(String[] args)
    {
        // Get the type of the FieldInfoGetFieldFromHandle class.
        Type myType = FieldInfoGetFieldFromHandle.class.ToType();

        // Get the fields of the FieldInfoGetFieldFromHandle 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].get_FieldHandle();

            // Call the GetFieldFromHandle method. 
            FieldInfo myFieldInfo = FieldInfo.GetFieldFromHandle(
                myRuntimeFieldHandle);

            // Display the FieldInfo of myFieldInfo.
            Console.WriteLine("{0}", myFieldInfo);
        }
    } //main
} //FieldInfoGetFieldFromHandle

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show: