英語で読む

次の方法で共有


Type.TypeHandle プロパティ

定義

現在の Type のハンドルを取得します。

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

プロパティ値

RuntimeTypeHandle

現在の Type のハンドル。

実装

例外

現在、.NET Compact Framework は、このプロパティをサポートしていません。

次の例では、対応する型のハンドルを返し、ハンドルから型を取得して表示するメソッドにハンドルを渡します。

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

注釈

TypeHandle 型を表す内部データ構造体へのポインターをカプセル化します。 このハンドルは、プロセスの有効期間中に一意です。 ハンドルは、取得されたアプリケーションドメインでのみ有効です。

適用対象

製品 バージョン
.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

こちらもご覧ください