Module.GetType Metoda
Definice
Vrátí zadaný typ.Returns the specified type.
Přetížení
GetType(String) |
Vrátí zadaný typ a provede vyhledávání citlivé na velká a malá písmena.Returns the specified type, performing a case-sensitive search. |
GetType(String, Boolean) |
Vrátí zadaný typ a hledá v modulu zadané citlivosti na velká a malá písmena.Returns the specified type, searching the module with the specified case sensitivity. |
GetType(String, Boolean, Boolean) |
Vrátí zadaný typ, který určuje, zda se má provést hledání v modulu, který rozlišuje velikost písmen a zda se má vyvolat výjimka, pokud nebyl nalezen typ.Returns the specified type, specifying whether to make a case-sensitive search of the module and whether to throw an exception if the type cannot be found. |
GetType(String)
Vrátí zadaný typ a provede vyhledávání citlivé na velká a malá písmena.Returns the specified type, performing a case-sensitive search.
public:
virtual Type ^ GetType(System::String ^ className);
[System.Runtime.InteropServices.ComVisible(true)]
public virtual Type GetType (string className);
override this.GetType : string -> Type
Public Overridable Function GetType (className As String) As Type
Parametry
- className
- String
Název typu, který se má najítThe name of the type to locate. Název musí být plně kvalifikovaný s oborem názvů.The name must be fully qualified with the namespace.
Návraty
Objekt Type
reprezentující daný typ, pokud je typ v tomto modulu; v opačném případě null
.A Type
object representing the given type, if the type is in this module; otherwise, null
.
- Atributy
Výjimky
className
je null
.className
is null
.
Inicializátory třídy jsou vyvolány a je vyvolána výjimka.The class initializers are invoked and an exception is thrown.
className
je řetězec s nulovou délkou.className
is a zero-length string.
className
vyžaduje závislé sestavení, které nebylo nalezeno.className
requires a dependent assembly that could not be found.
className
vyžaduje, aby bylo nalezeno závislé sestavení, ale nebylo možné ho načíst.className
requires a dependent assembly that was found but could not be loaded.
-nebo--or-
Aktuální sestavení bylo načteno do kontextu pouze pro reflexi a className
vyžaduje závislé sestavení, které nebylo předem načteno.The current assembly was loaded into the reflection-only context, and className
requires a dependent assembly that was not preloaded.
className
vyžaduje závislé sestavení, ale soubor není platným sestavením.className
requires a dependent assembly, but the file is not a valid assembly.
-nebo--or-
className
vyžaduje závislé sestavení, které bylo zkompilováno pro verzi modulu runtime později, než je aktuálně načtená verze.className
requires a dependent assembly which was compiled for a version of the runtime later than the currently loaded version.
Příklady
Následující příklad zobrazuje název typu v zadaném modulu.The following example displays the name of a type in the specified module.
using namespace System;
using namespace System::Reflection;
namespace ReflectionModule_Examples
{
public ref class MyMainClass{};
}
int main()
{
array<Module^>^moduleArray;
moduleArray = ReflectionModule_Examples::MyMainClass::typeid->Assembly->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 );
}
using System;
using System.Reflection;
namespace ReflectionModule_Examples
{
class MyMainClass
{
static void Main()
{
Module[] moduleArray;
moduleArray = typeof(MyMainClass).Assembly.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());
}
}
}
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 = GetType(MyMainClass).Assembly.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")
Console.WriteLine("Got type: {0}", myType.ToString())
End Sub
End Class
End Namespace 'ReflectionModule_Examples
Poznámky
Poznámka
Pokud byl typ předán jinému sestavení, je stále vrácen touto metodou.If the type has been forwarded to another assembly, it is still returned by this method. Informace o přesměrování typu najdete v tématu přesměrování typu v modulu CLR (Common Language Runtime).For information on type forwarding, see Type Forwarding in the Common Language Runtime.
Typ lze načíst z konkrétního modulu pomocí Module.GetType.A type can be retrieved from a specific module using Module.GetType. Volání Module.GetType v modulu, který obsahuje manifest, nebude prohledávat celé sestavení.Calling Module.GetType on the module that contains the manifest will not search the entire assembly. Chcete-li načíst typ ze sestavení bez ohledu na to, v jakém modulu je, je nutné volat Assembly.GetType.To retrieve a type from an assembly, regardless of which module it is in, you must call Assembly.GetType.
GetType(String, Boolean)
Vrátí zadaný typ a hledá v modulu zadané citlivosti na velká a malá písmena.Returns the specified type, searching the module with the specified case sensitivity.
public:
virtual Type ^ GetType(System::String ^ className, bool ignoreCase);
[System.Runtime.InteropServices.ComVisible(true)]
public virtual Type GetType (string className, bool ignoreCase);
override this.GetType : string * bool -> Type
Public Overridable Function GetType (className As String, ignoreCase As Boolean) As Type
Parametry
- className
- String
Název typu, který se má najítThe name of the type to locate. Název musí být plně kvalifikovaný s oborem názvů.The name must be fully qualified with the namespace.
- ignoreCase
- Boolean
true
pro hledání bez rozlišování velkých a malých písmen; v opačném případě false
.true
for case-insensitive search; otherwise, false
.
Návraty
Objekt Type
reprezentující daný typ, pokud je typ v tomto modulu; v opačném případě null
.A Type
object representing the given type, if the type is in this module; otherwise, null
.
- Atributy
Výjimky
className
je null
.className
is null
.
Inicializátory třídy jsou vyvolány a je vyvolána výjimka.The class initializers are invoked and an exception is thrown.
className
je řetězec s nulovou délkou.className
is a zero-length string.
className
vyžaduje závislé sestavení, které nebylo nalezeno.className
requires a dependent assembly that could not be found.
className
vyžaduje, aby bylo nalezeno závislé sestavení, ale nebylo možné ho načíst.className
requires a dependent assembly that was found but could not be loaded.
-nebo--or-
Aktuální sestavení bylo načteno do kontextu pouze pro reflexi a className
vyžaduje závislé sestavení, které nebylo předem načteno.The current assembly was loaded into the reflection-only context, and className
requires a dependent assembly that was not preloaded.
className
vyžaduje závislé sestavení, ale soubor není platným sestavením.className
requires a dependent assembly, but the file is not a valid assembly.
-nebo--or-
className
vyžaduje závislé sestavení, které bylo zkompilováno pro verzi modulu runtime později, než je aktuálně načtená verze.className
requires a dependent assembly which was compiled for a version of the runtime later than the currently loaded version.
Příklady
Následující příklad zobrazí název typu v zadaném modulu, zadáním false
pro parametr ignoreCase
, aby se případ neignoroval.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 namespace System;
using namespace System::Reflection;
namespace ReflectionModule_Examples
{
public ref class MyMainClass{};
}
int main()
{
array<Module^>^moduleArray;
moduleArray = ReflectionModule_Examples::MyMainClass::typeid->Assembly->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 );
}
using System;
using System.Reflection;
namespace ReflectionModule_Examples
{
class MyMainClass
{
static void Main()
{
Module[] moduleArray;
moduleArray = typeof(MyMainClass).Assembly.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());
}
}
}
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 = GetType(MyMainClass).Assembly.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
End Class
End Namespace 'ReflectionModule_Examples
Poznámky
Poznámka
Pokud byl typ předán jinému sestavení, je stále vrácen touto metodou.If the type has been forwarded to another assembly, it is still returned by this method. Informace o přesměrování typu najdete v tématu přesměrování typu v modulu CLR (Common Language Runtime).For information on type forwarding, see Type Forwarding in the Common Language Runtime.
Typ lze načíst z konkrétního modulu pomocí Module.GetType.A type can be retrieved from a specific module using Module.GetType. Volání Module.GetType v modulu, který obsahuje manifest, nebude prohledávat celé sestavení.Calling Module.GetType on the module that contains the manifest will not search the entire assembly. Chcete-li načíst typ ze sestavení bez ohledu na to, v jakém modulu je, je nutné volat Assembly.GetType.To retrieve a type from an assembly, regardless of which module it is in, you must call Assembly.GetType.
GetType(String, Boolean, Boolean)
Vrátí zadaný typ, který určuje, zda se má provést hledání v modulu, který rozlišuje velikost písmen a zda se má vyvolat výjimka, pokud nebyl nalezen typ.Returns the specified type, specifying whether to make a case-sensitive search of the module and whether to throw an exception if the type cannot be found.
public:
virtual Type ^ GetType(System::String ^ className, bool throwOnError, bool ignoreCase);
[System.Runtime.InteropServices.ComVisible(true)]
public virtual Type GetType (string className, bool throwOnError, bool ignoreCase);
override this.GetType : string * bool * bool -> Type
Public Overridable Function GetType (className As String, throwOnError As Boolean, ignoreCase As Boolean) As Type
Parametry
- className
- String
Název typu, který se má najítThe name of the type to locate. Název musí být plně kvalifikovaný s oborem názvů.The name must be fully qualified with the namespace.
- throwOnError
- Boolean
true
vyvolat výjimku, pokud nebyl nalezen typ; false
vrátit null
.true
to throw an exception if the type cannot be found; false
to return null
.
- ignoreCase
- Boolean
true
pro hledání bez rozlišování velkých a malých písmen; v opačném případě false
.true
for case-insensitive search; otherwise, false
.
Návraty
Objekt Type reprezentující zadaný typ, pokud je typ deklarovaný v tomto modulu; v opačném případě null
.A Type object representing the specified type, if the type is declared in this module; otherwise, null
.
- Atributy
Výjimky
className
je null
.className
is null
.
Inicializátory třídy jsou vyvolány a je vyvolána výjimka.The class initializers are invoked and an exception is thrown.
className
je řetězec s nulovou délkou.className
is a zero-length string.
throwOnError
je true
a typ nebyl nalezen.throwOnError
is true
, and the type cannot be found.
className
vyžaduje závislé sestavení, které nebylo nalezeno.className
requires a dependent assembly that could not be found.
className
vyžaduje, aby bylo nalezeno závislé sestavení, ale nebylo možné ho načíst.className
requires a dependent assembly that was found but could not be loaded.
-nebo--or-
Aktuální sestavení bylo načteno do kontextu pouze pro reflexi a className
vyžaduje závislé sestavení, které nebylo předem načteno.The current assembly was loaded into the reflection-only context, and className
requires a dependent assembly that was not preloaded.
className
vyžaduje závislé sestavení, ale soubor není platným sestavením.className
requires a dependent assembly, but the file is not a valid assembly.
-nebo--or-
className
vyžaduje závislé sestavení, které bylo zkompilováno pro verzi modulu runtime později, než je aktuálně načtená verze.className
requires a dependent assembly which was compiled for a version of the runtime later than the currently loaded version.
Příklady
Následující příklad zobrazuje název typu v zadaném modulu.The following example displays the name of a type in the specified module. Parametry throwOnError
a ignoreCase
jsou zadány jako false
.The throwOnError
and ignoreCase
parameters are specified as false
.
using namespace System;
using namespace System::Reflection;
namespace ReflectionModule_Examples
{
public ref class MyMainClass{};
}
int main()
{
array<Module^>^moduleArray;
moduleArray = ReflectionModule_Examples::MyMainClass::typeid->Assembly->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 );
}
using System;
using System.Reflection;
namespace ReflectionModule_Examples
{
class MyMainClass
{
static void Main()
{
Module[] moduleArray;
moduleArray = typeof(MyMainClass).Assembly.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());
}
}
}
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 = GetType(MyMainClass).Assembly.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
End Class
End Namespace 'ReflectionModule_Examples
Poznámky
Parametr throwOnError
ovlivňuje pouze to, co se stane, když typ nebyl nalezen.The throwOnError
parameter affects only what happens when the type is not found. Neovlivňuje žádné jiné výjimky, které by mohly být vyvolány.It does not affect any other exceptions that might be thrown. Konkrétně Pokud je typ nalezen, ale nelze načíst, TypeLoadException lze vyvolat i v případě, že throwOnError
je false
.In particular, if the type is found but cannot be loaded, TypeLoadException can be thrown even if throwOnError
is false
.
Poznámka
Pokud byl typ předán jinému sestavení, je stále vrácen touto metodou.If the type has been forwarded to another assembly, it is still returned by this method. Informace o přesměrování typu najdete v tématu přesměrování typu v modulu CLR (Common Language Runtime).For information on type forwarding, see Type Forwarding in the Common Language Runtime.
Typ lze načíst z konkrétního modulu pomocí Module.GetType.A type can be retrieved from a specific module using Module.GetType. Volání Module.GetType v modulu, který obsahuje manifest, nebude prohledávat celé sestavení.Calling Module.GetType on the module that contains the manifest will not search the entire assembly. Chcete-li načíst typ ze sestavení bez ohledu na to, v jakém modulu je, je nutné volat Assembly.GetType.To retrieve a type from an assembly, regardless of which module it is in, you must call Assembly.GetType.