本文整理匯總了VB.NET中System.Type.GetTypeHandle方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Type.GetTypeHandle方法的具體用法?VB.NET Type.GetTypeHandle怎麽用?VB.NET Type.GetTypeHandle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Type
的用法示例。
在下文中一共展示了Type.GetTypeHandle方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: MyClass1
' 導入命名空間
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()
' Get the RuntimeTypeHandle from an object.
Dim myRTHFromObject As RuntimeTypeHandle = Type.GetTypeHandle(myClass1)
' Get the RuntimeTypeHandle from a type.
Dim myRTHFromType As RuntimeTypeHandle = GetType(MyClass1).TypeHandle
Console.WriteLine(vbLf & "myRTHFromObject.Value: {0}", _
myRTHFromObject.Value)
Console.WriteLine("myRTHFromObject.GetType(): {0}", _
myRTHFromObject.GetType())
Console.WriteLine("Get the type back from the handle...")
Console.WriteLine("Type.GetTypeFromHandle(myRTHFromObject): {0}", _
Type.GetTypeFromHandle(myRTHFromObject))
Console.WriteLine(vbLf & "myRTHFromObject.Equals(myRTHFromType): {0}", _
myRTHFromObject.Equals(myRTHFromType))
Console.WriteLine(vbLf & "myRTHFromType.Value: {0}", _
myRTHFromType.Value)
Console.WriteLine("myRTHFromType.GetType(): {0}", _
myRTHFromType.GetType())
Console.WriteLine("Get the type back from the handle...")
Console.WriteLine("Type.GetTypeFromHandle(myRTHFromType): {0}", _
Type.GetTypeFromHandle(myRTHFromType))
End Sub
End Class
輸出:
myRTHFromObject.Value: 7549720 myRTHFromObject.GetType(): System.RuntimeTypeHandle Get the type back from the handle... Type.GetTypeFromHandle(myRTHFromObject): MyClass1 myRTHFromObject.Equals(myRTHFromType): True myRTHFromType.Value: 7549720 myRTHFromType.GetType(): System.RuntimeTypeHandle Get the type back from the handle... Type.GetTypeFromHandle(myRTHFromType): MyClass1