Windows apps
Collapse the table of content
Expand the table of content

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 struct RuntimeTypeHandle : 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.

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("\nmyRTHFromObject.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("\nmyRTHFromObject.Equals(myRTHFromType):  {0}", 
            myRTHFromObject.Equals(myRTHFromType));

        Console.WriteLine("\nmyRTHFromType.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));
    }
}

/* This code example produces output similar to the following:

myRTHFromObject.Value:  799464
myRTHFromObject.GetType():  System.RuntimeTypeHandle
Get the type back from the handle...
Type.GetTypeFromHandle(myRTHFromObject):  MyClass1

myRTHFromObject.Equals(myRTHFromType):  True

myRTHFromType.Value:  799464
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:
© 2017 Microsoft