Type.TypeHandle Type.TypeHandle Type.TypeHandle Type.TypeHandle Property

정의

현재 Type에 대한 핸들을 가져옵니다.Gets the handle for the current Type.

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

속성 값

현재 Type에 대한 핸들입니다.The handle for the current Type.

구현

예외

.NET Compact Framework에서는 현재 이 속성을 지원하지 않습니다.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 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

설명

TypeHandle 형식을 나타내는 내부 데이터 구조에 대 한 포인터를 캡슐화 합니다.TypeHandle encapsulates a pointer to an internal data structure that represents the type. 이 핸들은 프로세스 수명 동안 고유 합니다.This handle is unique during the process lifetime. 핸들을 얻은 애플리케이션 도메인에만 유효 합니다.The handle is valid only in the application domain in which it was obtained.

적용 대상

추가 정보