Type.TypeHandle Property
.NET Framework 4.5
Gets the handle for the current Type.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
| Exception | Condition |
|---|---|
| NotSupportedException | The .NET Compact Framework does not currently support this property. |
The following example returns the handle of the corresponding type and passes the handle to a method that gets the type from the handle and displays it.
using System; using System.Reflection; class MyClass { public int myField = 10; } class Type_TypeHandle { public static void Main() { try { MyClass myClass = new MyClass(); // Get the type of MyClass. Type myClassType = myClass.GetType(); // Get the runtime handle of MyClass. RuntimeTypeHandle myClassHandle = myClassType.TypeHandle; DisplayTypeHandle(myClassHandle); } catch(Exception e) { Console.WriteLine("Exception: {0}", e.Message ); } } public static void DisplayTypeHandle(RuntimeTypeHandle myTypeHandle) { // Get the type from the handle. Type myType = Type.GetTypeFromHandle(myTypeHandle); // Display the type. Console.WriteLine("\nDisplaying the type from the handle:\n"); Console.WriteLine("The type is {0}.", myType.ToString()); } }
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.