Module.GetType Method
Returns the specified class.
Overload List
Returns the specified class, performing a case-sensitive search.
Supported by the .NET Compact Framework.
[Visual Basic] Overloads Public Overridable Function GetType(String) As Type
[C#] public virtual Type GetType(string);
[C++] public: virtual Type* GetType(String*);
[JScript] public function GetType(String) : Type;
Returns the specified class, searching the module with the specified case sensitivity.
[Visual Basic] Overloads Public Overridable Function GetType(String, Boolean) As Type
[C#] public virtual Type GetType(string, bool);
[C++] public: virtual Type* GetType(String*, bool);
[JScript] public function GetType(String, Boolean) : Type;
Returns the specified class, searching the module with the specified case sensitivity and specifying whether to throw an exception if an error occurs while loading the Type.
[Visual Basic] Overloads Public Overridable Function GetType(String, Boolean, Boolean) As Type
[C#] public virtual Type GetType(string, bool, bool);
[C++] public: virtual Type* GetType(String*, bool, bool);
[JScript] public function GetType(String, Boolean, Boolean) : Type;
Inherited from Object.
Supported by the .NET Compact Framework.
[Visual Basic] Overloads Public Function GetType() As Type
[C#] public Type GetType();
[C++] public: Type* GetType();
[JScript] public function GetType() : Type;
Example
[Visual Basic, C#, C++] The following example displays the name of a class in the specified module. The throwOnError and ignoreCase parameters are specified as false.
[Visual Basic, C#, C++] Note This example shows how to use one of the overloaded versions of GetType. For other examples that might be available, see the individual overload topics.
[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 this class. Dim myModule As [Module] = moduleArray(0) Dim myType As Type myType = myModule.GetType("ReflectionModule_Examples.MyMainClass", False, 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 this class. Module myModule = moduleArray[0]; Type myType; myType = myModule.GetType("ReflectionModule_Examples.MyMainClass", false, 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 this class. Module* myModule = moduleArray[0]; Type* myType; myType = myModule->GetType(S"ReflectionModule_Examples.MyMainClass", false, 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
in the upper-left corner of the page.