O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required