Type.TypeHandle 속성

현재 Type에 대한 핸들을 가져옵니다.

네임스페이스: System
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
Public Overridable ReadOnly Property TypeHandle As RuntimeTypeHandle
‘사용 방법
Dim instance As Type
Dim value As RuntimeTypeHandle

value = instance.TypeHandle
public virtual RuntimeTypeHandle TypeHandle { get; }
public:
virtual property RuntimeTypeHandle TypeHandle {
    RuntimeTypeHandle get ();
}
/** @property */
public RuntimeTypeHandle get_TypeHandle ()
public function get TypeHandle () : RuntimeTypeHandle

속성 값

현재 Type에 대한 핸들입니다.

예외

예외 형식 조건

NotSupportedException

.NET Compact Framework에서는 현재 이 속성을 지원하지 않습니다.

설명

TypeHandle은 해당 형식을 나타내는 내부 데이터 구조에 대한 포인터를 캡슐화합니다. 이 핸들은 프로세스 실행 기간 동안 고유합니다. 핸들은 해당 핸들을 얻은 응용 프로그램 도메인에서만 유효합니다.

예제

다음 예제에서는 해당하는 형식의 핸들을 반환하여 이 핸들에서 형식을 가져오는 메서드에 전달한 다음 해당 핸들을 표시합니다.

Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
Class [MyClass]
    Public myField As Integer = 10
End Class '[MyClass]
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 'Main

    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 'DisplayTypeHandle
End Class 'Type_TypeHandle
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());
    }
}
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 );
   }

}
import System.*;
import System.Reflection.*;
class MyClass
{
    public int myField = 10;
} //MyClass

class Type_TypeHandle
{
    public static void main(String[] args)
    {
        try {
            MyClass myClass = new MyClass();
            // Get the type of MyClass.
            Type myClassType = myClass.GetType();
            // Get the runtime handle of MyClass.
            RuntimeTypeHandle myClassHandle = myClassType.get_TypeHandle();
            DisplayTypeHandle(myClassHandle);
        }
        catch (System.Exception e) {
            Console.WriteLine("Exception: {0}", e.get_Message());
        }
    } //main

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

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

Type 클래스
Type 멤버
System 네임스페이스
RuntimeTypeHandle 구조체
GetTypeHandle
GetTypeFromHandle