Redigeeri

Jagamisviis:


Type.ReflectionOnlyGetType(String, Boolean, Boolean) Method

Definition

Caution

ReflectionOnly loading is not supported and throws PlatformNotSupportedException.

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.

public:
 static Type ^ ReflectionOnlyGetType(System::String ^ typeName, bool throwIfNotFound, bool ignoreCase);
public static Type? ReflectionOnlyGetType (string typeName, bool throwIfNotFound, bool ignoreCase);
[System.Obsolete("ReflectionOnly loading is not supported and throws PlatformNotSupportedException.", DiagnosticId="SYSLIB0018", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public static Type? ReflectionOnlyGetType (string typeName, bool throwIfNotFound, bool ignoreCase);
public static Type ReflectionOnlyGetType (string typeName, bool throwIfNotFound, bool ignoreCase);
static member ReflectionOnlyGetType : string * bool * bool -> Type
[<System.Obsolete("ReflectionOnly loading is not supported and throws PlatformNotSupportedException.", DiagnosticId="SYSLIB0018", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
static member ReflectionOnlyGetType : string * bool * bool -> Type
Public Shared Function ReflectionOnlyGetType (typeName As String, throwIfNotFound As Boolean, ignoreCase As Boolean) As Type

Parameters

typeName
String

The assembly-qualified name of the Type to get.

throwIfNotFound
Boolean

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

ignoreCase
Boolean

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

Returns

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

Attributes

Exceptions

typeName is null.

A class initializer is invoked and throws an exception.

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.

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.

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

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

The assembly or one of its dependencies is not a valid assembly for the currently loaded runtime.

.NET Core and .NET 5+ only: In all cases.

Remarks

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.

Applies to

See also