Export (0) Print
Expand All

Module.GetType Method (String, Boolean)

Returns the specified type, searching the module with the specified case sensitivity.

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

[ComVisibleAttribute(true)]
public virtual Type GetType(
	string className,
	bool ignoreCase
)

Parameters

className
Type: System.String

The name of the type to locate. The name must be fully qualified with the namespace.

ignoreCase
Type: System.Boolean

true for case-insensitive search; otherwise, false.

Return Value

Type: System.Type
A Type object representing the given type, if the type is in this module; otherwise, null.

ExceptionCondition
ArgumentNullException

className is null.

TargetInvocationException

The class initializers are invoked and an exception is thrown.

ArgumentException

className is a zero-length string.

FileNotFoundException

className requires a dependent assembly that could not be found.

FileLoadException

className requires a dependent assembly that was found but could not be loaded.

-or-

The current assembly was loaded into the reflection-only context, and className requires a dependent assembly that was not preloaded.

BadImageFormatException

className requires a dependent assembly, but the file is not a valid assembly.

-or-

className requires a dependent assembly which was compiled for a version of the runtime later than the currently loaded version.

NoteNote:

If the type has been forwarded to another assembly, it is still returned by this method. For information on type forwarding, see Type Forwarding in the Common Language Runtime.

A type can be retrieved from a specific module using Module.GetType. Calling Module.GetType on the module that contains the manifest will not search the entire assembly. To retrieve a type from an assembly, regardless of which module it is in, you must call Assembly.GetType.

The following example displays the name of a type in the specified module, specifying false for the ignoreCase parameter so that case will not be ignored.

using System;
using System.Reflection;

namespace ReflectionModule_Examples
{
    class MyMainClass
    {
        static void Main()
        {
            Module[] moduleArray;

            moduleArray = Assembly.GetExecutingAssembly().GetModules(false);

            //In a simple project with only one module, the module at index 
            // 0 will be the module containing these classes.
            Module myModule = moduleArray[0];

            Type myType;
            myType = myModule.GetType("ReflectionModule_Examples.MyMainClass", false);
            Console.WriteLine("Got type: {0}", myType.ToString());
        }
    }
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft