Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
This topic has not yet been rated - Rate this topic

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 to perform a case-insensitive search; otherwise, false.

Return Value

Type: System.Type
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.

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.

Platform Notes

Silverlight for Windows Phone Silverlight for Windows Phone

 GetType does not throw ArgumentException when an empty string is passed as className. Instead, it returns null.

The following example gets a type in the currently executing module, specifying a string that has incorrect casing and specifying true for the ignoreCase parameter so that case is ignored.


using System;
using System.Reflection;

class Example
{
    public static void Demo(System.Windows.Controls.TextBlock outputBlock)
    {
        Module[] moduleArray;

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

        Module myModule = moduleArray[0];

        Type myType;

        myType = myModule.GetType("example", true);
        outputBlock.Text += String.Format("Found type: {0}\n", myType.ToString());
    }
}

/* This example produces output similar to the following:

Found type: Example
 */


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft. All rights reserved.