Mega Code Archive

 
Categories / C# / Reflection
 

FieldInfo GetFieldFromHandle Method gets a FieldInfo for the field represented by the specified handle

using System; using System.Reflection; public class MainClass {     public string x;     public char y;     public float a;     public int b;     public static void Main()     {         Type myType = typeof(MainClass);         FieldInfo [] myFieldInfoArray = myType.GetFields();         RuntimeFieldHandle myRuntimeFieldHandle;         for(int i = 0; i < myFieldInfoArray.Length; i++)         {             myRuntimeFieldHandle = myFieldInfoArray[i].FieldHandle;             FieldInfo myFieldInfo = FieldInfo.GetFieldFromHandle(myRuntimeFieldHandle);             Console.WriteLine("{0}", myFieldInfo);         }     } }