次の方法で共有


RuntimeTypeHandle 構造体

内部メタデータ トークンを使用する型を表します。

この型のすべてのメンバの一覧については、RuntimeTypeHandle メンバ を参照してください。

System.Object
   System.ValueType
      System.RuntimeTypeHandle

<Serializable>
Public Structure RuntimeTypeHandle   Implements ISerializable
[C#]
[Serializable]
public struct RuntimeTypeHandle : ISerializable
[C++]
[Serializable]
public __value struct RuntimeTypeHandle : public ISerializable

[JScript] JScript では、.NET Framework の構造体を利用することができます。ただし、独自に定義することはできません。

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

使用例

[Visual Basic, C#, C++] RuntimeTypeHandle を取得する方法を次の例に示します。

 
Imports System
Imports System.Reflection

 _
Public Class MyClass1
   Private x As Integer = 0
   
   Public Function MyMethod() As Integer
      Return x
   End Function 'MyMethod
End Class 'MyClass1
 _
Public Class MyClass2
   
   Public Shared Sub Main()
      Dim myClass1 As New MyClass1()
      
      ' Get the RuntimeTypeHandle from an object.
      Dim myRTHFromObject As RuntimeTypeHandle = Type.GetTypeHandle(myClass1)
      ' Get the RuntimeTypeHandle from a type.
      Dim myRTHFromType As RuntimeTypeHandle = GetType(MyClass1).TypeHandle
      
      Console.WriteLine("myRTHFromObject.Value: {0}", myRTHFromObject.Value)
      Console.WriteLine("myRTHFromObject.Type: {0}", myRTHFromObject.GetType())
      Console.WriteLine("myRTHFromType.Value: {0}", myRTHFromType.Value)
      Console.WriteLine("myRTHFromType.Type: {0}", myRTHFromType.GetType())
   End Sub 'Main 
End Class 'MyClass2

[C#] 
using System;
using System.Reflection;
public class MyClass1
{
    private int x=0;
    public int MyMethod()
    {
        return x;
    }
}
public class MyClass2
{
    public static void Main()
    {
        MyClass1 myClass1 = new MyClass1();

        // Get the RuntimeTypeHandle from an object.
        RuntimeTypeHandle myRTHFromObject = Type.GetTypeHandle(myClass1);
        // Get the RuntimeTypeHandle from a type.
        RuntimeTypeHandle myRTHFromType = typeof(MyClass1).TypeHandle;

        Console.WriteLine("myRTHFromObject.Value: {0}", myRTHFromObject.Value);
        Console.WriteLine("myRTHFromObject.Type: {0}", myRTHFromObject.GetType());
        Console.WriteLine("myRTHFromType.Value: {0}", myRTHFromType.Value);
        Console.WriteLine("myRTHFromType.Type: {0}", myRTHFromType.GetType());

    }
}

[C++] 
#using <mscorlib.dll>

using namespace System;
using namespace System::Reflection;

public __gc class MyClass1 {
private:
   int x;
public:
   int MyMethod() {
      return x;
   }
};

int main() {
   MyClass1* myClass1 = new MyClass1();

   // Get the RuntimeTypeHandle from an object.
   RuntimeTypeHandle myRTHFromObject = Type::GetTypeHandle(myClass1);
   // Get the RuntimeTypeHandle from a type.
   RuntimeTypeHandle myRTHFromType = __typeof(MyClass1)->TypeHandle;

   Console::WriteLine(S"myRTHFromObject.Value: {0}",__box( myRTHFromObject.Value));
   Console::WriteLine(S"myRTHFromObject.Type: {0}", __box(myRTHFromObject)->GetType());
   Console::WriteLine(S"myRTHFromType.Value: {0}",__box( myRTHFromType.Value));
   Console::WriteLine(S"myRTHFromType.Type: {0}", __box(myRTHFromType)->GetType());

}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

アセンブリ: Mscorlib (Mscorlib.dll 内)

参照

RuntimeTypeHandle メンバ | System 名前空間