Leer en inglés

Compartir a través de


Type.TypeHandle Propiedad

Definición

Obtiene el identificador del objeto Type actual.

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

Valor de propiedad

RuntimeTypeHandle

Identificador del objeto Type actual.

Implementaciones

Excepciones

.NET Compact Framework no admite actualmente esta propiedad.

Ejemplos

En el ejemplo siguiente se devuelve el identificador del tipo correspondiente y se pasa el identificador a un método que obtiene el tipo del identificador y lo muestra.

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

Comentarios

TypeHandle encapsula un puntero a una estructura de datos interna que representa el tipo. Este identificador es único durante la vigencia del proceso. El identificador solo es válido en el dominio de aplicación en el que se obtuvo.

Se aplica a

Producto Versiones
.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

Consulte también