Export (0) Print
Expand All

Module.GetType Method (String, Boolean)

.NET Framework 1.1

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

[Visual Basic]
Overloads Public Overridable Function GetType( _
   ByVal className As String, _
   ByVal ignoreCase As Boolean _
) As Type
[C#]
public virtual Type GetType(
 string className,
 bool ignoreCase
);
[C++]
public: virtual Type* GetType(
 String* className,
 bool ignoreCase
);
[JScript]
public function GetType(
   className : String,
 ignoreCase : Boolean
) : Type;

Parameters

className
The name of the class 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 class name, if the class is in this module; otherwise, a null reference (Nothing in Visual Basic).

Exceptions

Exception Type Condition
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, such as if it is greater than 1023 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.

Example

[Visual Basic, C#, C++] The following example displays the name of a class in the specified module, specifying false for the ignoreCase parameter so that case will not be ignored.

[Visual Basic] 
Imports System
Imports System.Reflection

'This code assumes that the root namespace is set to empty("").
Namespace ReflectionModule_Examples
    Class MyMainClass
        Shared Sub Main()
            Dim moduleArray() As [Module]

            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.
            Dim myModule As [Module] = moduleArray(0)

            Dim myType As Type
            myType = myModule.GetType("ReflectionModule_Examples.MyMainClass", False)
            Console.WriteLine("Got type: {0}", myType.ToString())
        End Sub 'Main
    End Class 'MyMainClass
End Namespace 'ReflectionModule_Examples

[C#] 
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());
        }
    }
}

[C++] 
#using <mscorlib.dll>

using namespace System;
using namespace System::Reflection;

namespace ReflectionModule_Examples
{
   public __gc class MyMainClass
   {
   };
}

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

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

Module Class | Module Members | System.Reflection Namespace | Module.GetType Overload List

Show:
© 2015 Microsoft