Export (0) Print
Expand All
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
)
/** @attribute ComVisibleAttribute(true) */ 
public Type GetType (
	String className, 
	boolean ignoreCase
)
ComVisibleAttribute(true) 
public function GetType (
	className : String, 
	ignoreCase : boolean
) : Type

Parameters

className

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

ignoreCase

true for case-insensitive search; otherwise, false.

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 invalid, for example if it contains invalid characters, or if it is a zero-length string.

SecurityException

The caller does not have the required reflection permissions and attempts to reflect on a type that is not public.

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());
        }
    }
}

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

Windows 98, Windows 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.