FieldInfo.GetFieldFromHandle
Imports System
Imports System.Reflection
Public Class Test(Of T)
Public TestField As T
End Class
Public Class Example
Public Shared Sub Main()
Dim rth As RuntimeTypeHandle = GetType(Test(Of String)).TypeHandle
Dim rfh As RuntimeFieldHandle = GetType(Test(Of String)).GetField("TestField").FieldHandle
Try
Dim f1 As FieldInfo = FieldInfo.GetFieldFromHandle(rfh)
Catch ex As Exception
Console.WriteLine("{0}: {1}", ex.GetType().Name, ex.Message)
End Try
Dim fi As FieldInfo = FieldInfo.GetFieldFromHandle(rfh, rth)
Console.WriteLine(fi.Name)
Console.WriteLine(fi.FieldType)
fi = FieldInfo.GetFieldFromHandle(rfh, GetType(Test(Of Object)).TypeHandle)
Console.WriteLine(fi.Name)
Console.WriteLine(fi.FieldType)
Try
fi = FieldInfo.GetFieldFromHandle(rfh,GetType(Test(Of Integer)).TypeHandle)
Catch ex As Exception
Console.WriteLine(vbCrLf & "{0}: {1}", ex.GetType().Name, ex.Message)
End Try
End Sub
End Class
Related examples in the same category