다음을 통해 공유


FieldInfo.GetFieldFromHandle Method (RuntimeFieldHandle)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

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

Syntax

'Declaration
Public Shared Function GetFieldFromHandle ( _
    handle As RuntimeFieldHandle _
) As FieldInfo
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.

Exceptions

Exception Condition
ArgumentException

handle is invalid.

MethodAccessException

The member is invoked late-bound through mechanisms such as Type.InvokeMember.

Remarks

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

Examples

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

Version Information

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

Platforms

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