Type.TypeHandle Property
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Gets the handle for the current Type.
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.
Note: |
|---|
To run this example, see Building examples that have static TextBlock controls for Windows Phone 8. |
using System; using System.Reflection; class MyClass { public int myField = 10; } class Example { public static void Demo(System.Windows.Controls.TextBlock outputBlock) { 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(outputBlock, myClassHandle); } catch (Exception e) { outputBlock.Text += String.Format("Exception: {0}", e.Message) + "\n"; } } public static void DisplayTypeHandle(System.Windows.Controls.TextBlock outputBlock, RuntimeTypeHandle myTypeHandle) { // Get the type from the handle. Type myType = Type.GetTypeFromHandle(myTypeHandle); // Display the type. outputBlock.Text += "\nDisplaying the type from the handle:\n" + "\n"; outputBlock.Text += String.Format("The type is {0}.", myType.ToString()) + "\n"; } }
Show:
Note: