Type.TypeHandle Proprietà

Definizione

che rappresenta il nome dell'oggetto Type corrente.

C#
public virtual RuntimeTypeHandle TypeHandle { get; }
C#
public abstract RuntimeTypeHandle TypeHandle { get; }

Valore della proprietà

RuntimeTypeHandle

Handle per l'oggetto Type corrente.

Implementazioni

Eccezioni

Questa proprietà non è attualmente supportata in .NET Compact Framework.

Esempio

Nell'esempio seguente viene restituito l'handle del tipo corrispondente e l'handle viene passato a un metodo che ottiene il tipo dall'handle e lo visualizza.

C#
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());
    }
}

Commenti

TypeHandle incapsula un puntatore a una struttura di dati interna che rappresenta il tipo. Questo handle è univoco durante la durata del processo. L'handle è valido solo nel dominio applicazione in cui è stato ottenuto.

Si applica a

Prodotto Versioni
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

Vedi anche