Export (0) Print
Expand All

FieldInfo.GetFieldFromHandle Method (RuntimeFieldHandle)

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

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

'Declaration
Public Shared Function GetFieldFromHandle ( _
	handle As RuntimeFieldHandle _
) As FieldInfo

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.FieldInfo
A FieldInfo object representing the field specified by handle.

ExceptionCondition
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.

Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic

Public Class FieldInfo_GetFieldFromHandle
    Public x As String 
    Public y As Char 
    Public a As Single 
    Public b As Integer 

    Public Shared Sub Main()
        ' Get the type of the FieldInfo_GetFieldFromHandle class. 
        Dim myType As Type = GetType(FieldInfo_GetFieldFromHandle)
        ' Get the fields of the FieldInfo_GetFieldFromHandle class. 
        Dim myFieldInfoArray As FieldInfo() = myType.GetFields()
        Console.WriteLine(ControlChars.NewLine & _
           "The field information of the declared" & _
           " fields x, y, a, and b is:" & ControlChars.NewLine)
        Dim myRuntimeFieldHandle As RuntimeFieldHandle
        Dim i As Integer 
        For i = 0 To myFieldInfoArray.Length - 1
            ' Get the RuntimeFieldHandle of myFieldInfoArray.
            myRuntimeFieldHandle = myFieldInfoArray(i).FieldHandle
            ' Call the GetFieldFromHandle method.  
            Dim myFieldInfo As FieldInfo = FieldInfo.GetFieldFromHandle(myRuntimeFieldHandle)
            ' Display the FieldInfo of myFieldInfo.
            Console.WriteLine("{0}", myFieldInfo)
        Next i
    End Sub 'Main
End Class 'FieldInfo_GetFieldFromHandle

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

Show:
© 2015 Microsoft