GetFieldFromHandle Method (RuntimeFieldHandle)
Collapse the table of content
Expand the table of content

FieldInfo.GetFieldFromHandle Method (RuntimeFieldHandle)

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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


Imports System.Reflection

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

   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      ' Get the type of the Example class.
      Dim myType As Type = GetType(Example)
      ' Get the fields of the Example class.
      Dim myFieldInfoArray As FieldInfo() = myType.GetFields()
      outputBlock.Text &= ControlChars.NewLine & _
         "The field information of the declared" & _
         " fields x, y, a, and b is:" & ControlChars.NewLine & vbCrLf
      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.
         outputBlock.Text &= String.Format("{0}", myFieldInfo) & vbCrLf
      Next i
   End Sub 'Main
End Class 'FieldInfo_GetFieldFromHandle


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft