Get Type Information from a Class or an Object

Problem

You want to retrieve information about any .NET type (class, interface, structure, enumeration, and so on).

Solution

Use the Visual Basic .NET command GetType with the class name. Or use the Object.GetType instance method with any object.

Discussion

The System.Type class is one of the core ingredients in reflection. It allows you to retrieve information about any .NET type and drill down to examine type members such as methods, properties, events, and fields. To retrieve a Type object for a given class, you use the Visual Basic GetType command, as shown here:

' Retrieve information about the System.Xml.XmlDocument class.
Dim TypeInfo As Type
TypeInfo = GetType(System.Xml.XmlDocument)

Alternatively, ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.