Mega Code Archive

 
Categories / VB.Net / Reflection
 

Type GetTypeHandle gets the handle for the Type of a specified object

Imports System Imports System.Reflection Public Class MyClass1     Private x As Integer = 0     Public Function MyMethod() As Integer         Return x     End Function 'MyMethod End Class Public Class MyClass2     Public Shared Sub Main()         Dim myClass1 As New MyClass1()         Dim myRTHFromObject As RuntimeTypeHandle = Type.GetTypeHandle(myClass1)         Dim myRTHFromType As RuntimeTypeHandle = GetType(MyClass1).TypeHandle         Console.WriteLine(myRTHFromObject.Value)         Console.WriteLine(myRTHFromObject.GetType())         Console.WriteLine(Type.GetTypeFromHandle(myRTHFromObject))         Console.WriteLine(myRTHFromObject.Equals(myRTHFromType))         Console.WriteLine(myRTHFromType.Value)         Console.WriteLine(myRTHFromType.GetType())         Console.WriteLine(Type.GetTypeFromHandle(myRTHFromType))     End Sub End Class