RuntimeTypeHandle Structure

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Represents a type using an internal metadata token.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

<SerializableAttribute>
<ComVisibleAttribute(True)>
Public Structure RuntimeTypeHandle
	Implements ISerializable

NameDescription
System_CAPS_pubpropertyValue

Gets a handle to the type represented by this instance.

NameDescription
System_CAPS_pubmethodEquals(Object)

Indicates whether the specified object is equal to the current RuntimeTypeHandle structure.(Overrides ValueType.Equals(Object).)

System_CAPS_pubmethodEquals(RuntimeTypeHandle)

Indicates whether the specified RuntimeTypeHandle structure is equal to the current RuntimeTypeHandle structure.

System_CAPS_pubmethodGetHashCode()

Returns the hash code for the current instance.(Overrides ValueType.GetHashCode().)

System_CAPS_pubmethodGetModuleHandle()

Gets a handle to the module that contains the type represented by the current instance.

System_CAPS_pubmethodGetObjectData(SerializationInfo, StreamingContext)

Populates a SerializationInfo with the data necessary to deserialize the type represented by the current instance.

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodToString()

Returns the fully qualified type name of this instance.(Inherited from ValueType.)

NameDescription
System_CAPS_puboperatorSystem_CAPS_staticEquality(Object, RuntimeTypeHandle)

Indicates whether an object and a RuntimeTypeHandle structure are equal.

System_CAPS_puboperatorSystem_CAPS_staticEquality(RuntimeTypeHandle, Object)

Indicates whether a RuntimeTypeHandle structure is equal to an object.

System_CAPS_puboperatorSystem_CAPS_staticInequality(Object, RuntimeTypeHandle)

Indicates whether an object and a RuntimeTypeHandle structure are not equal.

System_CAPS_puboperatorSystem_CAPS_staticInequality(RuntimeTypeHandle, Object)

Indicates whether a RuntimeTypeHandle structure is not equal to an object.

The following example demonstrates how to obtain a RuntimeTypeHandlefrom a type or from an object, and how to turn the handle back into a type.

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 

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(vbLf & "myRTHFromObject.Value:  {0}", _
            myRTHFromObject.Value)
        Console.WriteLine("myRTHFromObject.GetType():  {0}", _
            myRTHFromObject.GetType())
        Console.WriteLine("Get the type back from the handle...")
        Console.WriteLine("Type.GetTypeFromHandle(myRTHFromObject):  {0}", _
            Type.GetTypeFromHandle(myRTHFromObject))

        Console.WriteLine(vbLf & "myRTHFromObject.Equals(myRTHFromType):  {0}", _
            myRTHFromObject.Equals(myRTHFromType))

        Console.WriteLine(vbLf & "myRTHFromType.Value:  {0}", _
            myRTHFromType.Value)
        Console.WriteLine("myRTHFromType.GetType():  {0}", _
            myRTHFromType.GetType())
        Console.WriteLine("Get the type back from the handle...")
        Console.WriteLine("Type.GetTypeFromHandle(myRTHFromType):  {0}", _
            Type.GetTypeFromHandle(myRTHFromType))
    End Sub 
End Class 

' This code example produces output similar to the following:
'
'myRTHFromObject.Value:  7549720
'myRTHFromObject.GetType():  System.RuntimeTypeHandle
'Get the type back from the handle...
'Type.GetTypeFromHandle(myRTHFromObject):  MyClass1
'
'myRTHFromObject.Equals(myRTHFromType):  True
'
'myRTHFromType.Value:  7549720
'myRTHFromType.GetType():  System.RuntimeTypeHandle
'Get the type back from the handle...
'Type.GetTypeFromHandle(myRTHFromType):  MyClass1

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: