This documentation is archived and is not being maintained.

Viewing Type Information

The System::Type class is central to reflection. The common language runtime creates the Type for a loaded type when reflection requests it. You can use a Type object's methods, fields, properties, and nested classes to find out everything about that type.

Use Assembly::GetType or Assembly::GetTypes to obtain Type objects from assemblies that have not been loaded, passing in the name of the type or types you want. Use Type::GetType to get the Type objects from an assembly that is already loaded. Use Module::GetType and Module::GetTypes to obtain module Type objects.

NoteNote:

If you want to examine and manipulate generic types and methods, please see the additional information provided in Reflection and Generic Types and How to: Examine and Instantiate Generic Types with Reflection.

The following example shows the syntax necessary to get the Assembly object and module for an assembly.

No code example is currently available or this language may not be supported.

The following example demonstrates getting Type objects from a loaded assembly.

No code example is currently available or this language may not be supported.

Once you obtain a Type, there are many ways you can discover information about the members of that type. For example, you can find out about all the type's members by calling the Type::GetMembers method, which obtains an array of MemberInfo objects describing each of the members of the current type.

You can also use methods on the Type class to retrieve information about one or more constructors, methods, events, fields, or properties that you specify by name. For example, Type::GetConstructor encapsulates a specific constructor of the current class.

If you have a Type, you can use the Type::Module property to obtain an object that encapsulates the module containing that type. Use the Module::Assembly property to locate an object that encapsulates the assembly containing the module. You can obtain the assembly that encapsulates the type directly by using the Type::Assembly property.

The following example shows how to list the constructors for a class, in this case, the String class.

No code example is currently available or this language may not be supported.

Obtain information about the type's methods, properties, events, and fields using MemberInfo, MethodInfo, FieldInfo, or PropertyInfo objects.

The following example uses MemberInfo to list the number of members in the System.IO.File class and uses the System.Type.IsPublic property to determine the visibility of the class.

No code example is currently available or this language may not be supported.

The following example investigates the type of the specified member. It performs reflection on a member of the MemberInfo class, and lists its type.

No code example is currently available or this language may not be supported.

The following example uses all the Reflection *Info classes along with BindingFlags to list all the members (constructors, fields, properties, events, and methods) of the specified class, dividing the members into static and instance categories.

No code example is currently available or this language may not be supported.
Show: