Type.GetTypeHandle Method
.NET Framework 3.0
Gets the handle for the Type of a specified object.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly: mscorlib (in mscorlib.dll)
public static RuntimeTypeHandle GetTypeHandle ( Object o )
public static function GetTypeHandle ( o : Object ) : RuntimeTypeHandle
Not applicable.
Parameters
- o
The Object for which to get the Type handle.
Return Value
The handle for the Type of the specified Object.The following example defines the class MyClass1, gets an instance of it, and retrieves the runtime handle of the object.
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
Windows 98, Windows Server 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
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.Community Additions
ADD
Show: