Export (0) Print
Expand All

Module.GetType Method (String)

Returns the specified type, performing a case-sensitive search.

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

[ComVisibleAttribute(true)] 
public virtual Type GetType (
	string className
)
/** @attribute ComVisibleAttribute(true) */ 
public Type GetType (
	String className
)
ComVisibleAttribute(true) 
public function GetType (
	className : String
) : Type
Not applicable.

Parameters

className

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

Return Value

A Type object representing the given type, if the type is in this module; otherwise, a null reference (Nothing in Visual Basic).

Exception typeCondition

ArgumentNullException

className is a null reference (Nothing in Visual Basic).

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.

The following example displays the name of a type in the specified module.

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");
            Console.WriteLine("Got type: {0}", myType.ToString());
        }
    }
}

package ReflectionModule_Examples;
import System.*;
import System.Reflection.*;

class MyMainClass
{

    public static void main(String[] args)
    {
        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 = (Module)moduleArray.get_Item(0);
        Type myType;
        myType = myModule.GetType("ReflectionModule_Examples.MyMainClass");
        Console.WriteLine("Got type: {0}", myType.ToString());
    } //main
} //MyMainClass   

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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft