FieldInfo.FieldHandle Property gets a RuntimeFieldHandle : FieldInfo « Reflection « VB.Net






FieldInfo.FieldHandle Property gets a RuntimeFieldHandle

 

Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic

Public Class [MyClass]
    Public MyField As String = "MyField"
End Class 

Public Class FieldInfo_FieldHandle
    Public Shared Sub Main()
        Dim [myClass] As New [MyClass]()
        Dim myType As Type = GetType([MyClass])
        Try
            Dim myFieldInfo As FieldInfo = myType.GetField("MyField", BindingFlags.Public Or BindingFlags.Instance)
            If Not (myFieldInfo Is Nothing) Then
                Dim myFieldHandle As RuntimeFieldHandle = myFieldInfo.FieldHandle

                DisplayFieldHandle(myFieldHandle)
            Else
                Console.WriteLine("The myFieldInfo object is null.")
            End If
        Catch e As Exception
            Console.WriteLine(" Exception: {0}", e.Message.ToString())
        End Try
    End Sub

    Public Shared Sub DisplayFieldHandle(ByVal myFieldHandle As RuntimeFieldHandle)
        Dim myField As FieldInfo = FieldInfo.GetFieldFromHandle(myFieldHandle)
        Console.WriteLine(ControlChars.Cr + "Displaying the field from the handle." + ControlChars.Cr)
        Console.WriteLine("The type is {0}.", myField.ToString())
    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.FieldType Property gets the type of this field object.
4.FieldInfo.GetFieldFromHandle gets a FieldInfo for the field represented by the specified handle.
5.FieldInfo.GetFieldFromHandle
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.