FieldInfo.GetFieldFromHandle : FieldInfo « Reflection « VB.Net






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

1.FieldInfo Class represents the attributes of a field and provides access to field metadata.
2.FieldInfo.Attributes Property gets the attributes associated with this field.
3.FieldInfo.FieldHandle Property gets a RuntimeFieldHandle
4.FieldInfo.FieldType Property gets the type of this field object.
5.FieldInfo.GetFieldFromHandle gets a FieldInfo for the field represented by the specified handle.
6.FieldInfo.GetValue Method returns the value of a field supported by a given object.
7.FieldInfo Get Value
8.FieldInfo.IsAssembly
9.FieldInfo.IsInitOnly Property tells whether the field can only be set in the body of the constructor.
10.FieldInfo.IsNotSerialized
11.FieldInfo.IsPinvokeImpl
12.FieldInfo.IsPrivate
13.FieldInfo.IsPublic
14.FieldInfo.IsSpecialName tells whether the SpecialName attribute is set in the FieldAttributes enumerator.
15.FieldInfo.IsStatic
16.FieldInfo.MemberType
17.FieldInfo.SetValue sets the value of the field supported by the given object.