Export (0) Print
Expand All
Expand Minimize

Type::ReflectionOnlyGetType Method

Gets the Type with the specified name, specifying whether to perform a case-sensitive search and whether to throw an exception if the type is not found. The type is loaded for reflection only, not for execution.

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

public:
static Type^ ReflectionOnlyGetType(
	String^ typeName, 
	bool throwIfNotFound, 
	bool ignoreCase
)

Parameters

typeName
Type: System::String

The assembly-qualified name of the Type to get.

throwIfNotFound
Type: System::Boolean

true to throw a TypeLoadException if the type cannot be found; false to return nullptr if the type cannot be found. Specifying false also suppresses some other exception conditions, but not all of them. See the Exceptions section.

ignoreCase
Type: System::Boolean

true to perform a case-insensitive search for typeName; false to perform a case-sensitive search for typeName.

Return Value

Type: System::Type
The type with the specified name, if found; otherwise, nullptr. If the type is not found, the throwIfNotFound parameter specifies whether nullptr is returned or an exception is thrown. In some cases, an exception is thrown regardless of the value of throwIfNotFound. See the Exceptions section.

ExceptionCondition
ArgumentNullException

typeName is nullptr.

TargetInvocationException

A class initializer is invoked and throws an exception.

TypeLoadException

throwIfNotFound is true and the type is not found.

-or-

throwIfNotFound is true and typeName contains invalid characters, such as an embedded tab.

-or-

throwIfNotFound is true and typeName is an empty string.

-or-

throwIfNotFound is true and typeName represents an array type with an invalid size.

-or-

typeName represents an array of TypedReference objects.

ArgumentException

typeName does not include the assembly name.

-or-

throwIfNotFound is true and typeName contains invalid syntax; for example, "MyType[,*,]".

-or-

typeName represents a generic type that has a pointer type, a ByRef type, or Void as one of its type arguments.

-or-

typeName represents a generic type that has an incorrect number of type arguments.

-or-

typeName represents a generic type, and one of its type arguments does not satisfy the constraints for the corresponding type parameter.

FileNotFoundException

throwIfNotFound is true and the assembly or one of its dependencies was not found.

FileLoadException

The assembly or one of its dependencies was found, but could not be loaded.

BadImageFormatException

The assembly or one of its dependencies is not valid.

-or-

The assembly was compiled with a later version of the common language runtime than the version that is currently loaded.

If the assembly containing the type is not already loaded into the reflection-only context, using the ReflectionOnlyGetType method is equivalent to first loading the assembly for reflection only, using the ReflectionOnlyLoad method, and then loading the type by calling the assembly's Assembly::GetType method. For information about assembly-qualified names, see the Type::AssemblyQualifiedName property. For additional details on specifying type names, see the GetType(String, Boolean, Boolean) method overload.

If the assembly is already loaded for execution, another copy is loaded into the reflection-only context.

The throwIfNotFound parameter specifies what happens when the type is not found, and also suppresses certain other exception conditions, as described in the Exceptions section. Some exceptions are thrown regardless of the value of throwIfNotFound. For example, if the assembly is not valid, a BadImageFormatException is thrown even if throwIfNotFound is false.

For more information about using the reflection-only context, see How to: Load Assemblies into the Reflection-Only Context.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft