Type.GetTypeHandle-Methode
Ruft das Handle für den Type eines angegebenen Objekts ab.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public Shared Function GetTypeHandle ( _
o As Object _
) As RuntimeTypeHandle
'Usage
Dim o As Object
Dim returnValue As RuntimeTypeHandle
returnValue = Type.GetTypeHandle(o)
public static RuntimeTypeHandle GetTypeHandle (
Object o
)
public:
static RuntimeTypeHandle GetTypeHandle (
Object^ o
)
public static RuntimeTypeHandle GetTypeHandle (
Object o
)
public static function GetTypeHandle (
o : Object
) : RuntimeTypeHandle
Parameter
- o
Das Object, für das das Typhandle abgerufen werden soll.
Rückgabewert
Das Handle für den Type des angegebenen Object.
Hinweise
Die Handles sind nur in der Anwendungsdomäne gültig, in der sie angefordert wurden.
Beispiel
Im folgenden Beispiel wird die MyClass1
-Klasse definiert. Anschließend werden eine Instanz dieser Klasse und das Laufzeithandle des Objekts abgerufen.
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
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());
}
}
using namespace System;
using namespace System::Reflection;
public ref class MyClass1
{
private:
int x;
public:
int MyMethod()
{
return x;
}
};
int main()
{
MyClass1^ myClass1 = gcnew MyClass1;
// Get the RuntimeTypeHandle from an object.
RuntimeTypeHandle myRTHFromObject = Type::GetTypeHandle( myClass1 );
// Get the RuntimeTypeHandle from a type.
RuntimeTypeHandle myRTHFromType = MyClass1::typeid->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() );
}
import System.*;
import System.Reflection.*;
public class MyClass1
{
private int x = 0;
public int MyMethod()
{
return x;
} //MyMethod
} //MyClass1
public class MyClass2
{
public static void main(String[] args)
{
MyClass1 myClass1 = new MyClass1();
// Get the RuntimeTypeHandle from an object.
RuntimeTypeHandle myRTHFromObject = Type.GetTypeHandle(myClass1);
// Get the RuntimeTypeHandle from a type.
RuntimeTypeHandle myRTHFromType = (MyClass1.class.ToType()).
get_TypeHandle();
Console.WriteLine("myRTHFromObject.Value: {0}", myRTHFromObject.
get_Value());
Console.WriteLine("myRTHFromObject.Type: {0}", myRTHFromObject.
GetType());
Console.WriteLine("myRTHFromType.Value: {0}", myRTHFromType.
get_Value());
Console.WriteLine("myRTHFromType.Type: {0}", myRTHFromType.
GetType());
}//main
} //MyClass2
Plattformen
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
Type-Klasse
Type-Member
System-Namespace
RuntimeTypeHandle-Struktur
TypeHandle
GetTypeFromHandle