Type.TypeHandle Propriedade

Definição

Obtém o identificador do Type atual.

public:
 virtual property RuntimeTypeHandle TypeHandle { RuntimeTypeHandle get(); };
public:
 abstract property RuntimeTypeHandle TypeHandle { RuntimeTypeHandle get(); };
public virtual RuntimeTypeHandle TypeHandle { get; }
public abstract RuntimeTypeHandle TypeHandle { get; }
member this.TypeHandle : RuntimeTypeHandle
Public Overridable ReadOnly Property TypeHandle As RuntimeTypeHandle
Public MustOverride ReadOnly Property TypeHandle As RuntimeTypeHandle

Valor da propriedade

RuntimeTypeHandle

O identificador do Type atual.

Implementações

Exceções

No momento, o .NET Compact Framework não dá suporte a essa propriedade.

Exemplos

O exemplo a seguir retorna o identificador do tipo correspondente e passa o identificador para um método que obtém o tipo do identificador e o exibe.

using namespace System;
using namespace System::Reflection;
ref class MyClass
{
public:
   int myField;
};

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

int main()
{
   try
   {
      MyClass^ myClass = gcnew 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 );
   }

}
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());
    }
}
Imports System.Reflection

Class [MyClass]
    Public myField As Integer = 10
End Class
Class Type_TypeHandle
    Public Shared Sub Main()
        Try
            Dim [myClass] As New [MyClass]()

            ' Get the type of MyClass.
            Dim myClassType As Type = [myClass].GetType()

            ' Get the runtime handle of MyClass.
            Dim myClassHandle As RuntimeTypeHandle = myClassType.TypeHandle

            DisplayTypeHandle(myClassHandle)
        Catch e As Exception
            Console.WriteLine("Exception: {0}", e.Message.ToString())
        End Try
    End Sub

    Public Shared Sub DisplayTypeHandle(ByVal myTypeHandle As RuntimeTypeHandle)
        ' Get the type from the handle.
        Dim myType As Type = Type.GetTypeFromHandle(myTypeHandle)
        ' Display the type.
        Console.WriteLine(ControlChars.NewLine + "Displaying the type from the handle:" + ControlChars.NewLine)
        Console.WriteLine("The type is {0}.", myType.ToString())
    End Sub
End Class

Comentários

TypeHandle encapsula um ponteiro para uma estrutura de dados interna que representa o tipo. Esse handle é exclusivo durante o tempo de vida do processo. O handle é válido somente no domínio do aplicativo no qual ele foi obtido.

Aplica-se a

Confira também