Type.ReflectionOnlyGetType(String, Boolean, Boolean) Type.ReflectionOnlyGetType(String, Boolean, Boolean) Type.ReflectionOnlyGetType(String, Boolean, Boolean) Type.ReflectionOnlyGetType(String, Boolean, Boolean) Method

定义

获取具有指定名称的 Type,指定是否执行区分大小写的搜索,以及在找不到类型时是否引发异常。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);
static member ReflectionOnlyGetType : string * bool * bool -> Type
Public Shared Function ReflectionOnlyGetType (typeName As String, throwIfNotFound As Boolean, ignoreCase As Boolean) As Type

参数

typeName
String String String String

要获取的 Type 的程序集限定名称。The assembly-qualified name of the Type to get.

throwIfNotFound
Boolean Boolean Boolean Boolean

如果为 true,则会在找不到该类型时引发 TypeLoadException;如果为 false,则在找不到该类型时返回 nulltrue to throw a TypeLoadException if the type cannot be found; false to return null if the type cannot be found. 指定 false 还会取消某些其他异常条件,但并不取消所有条件。Specifying false also suppresses some other exception conditions, but not all of them. 请参见“异常”部分。See the Exceptions section.

ignoreCase
Boolean Boolean Boolean Boolean

如果为 true,则执行不区分大小写的 typeName 搜索;如果为 false,则执行区分大小写的 typeName 搜索。true to perform a case-insensitive search for typeName; false to perform a case-sensitive search for typeName.

返回

具有指定名称的类型(如果找到的话);否则为 nullThe type with the specified name, if found; otherwise, null. 如果找不到该类型,则 throwIfNotFound 参数指定是返回 null 还是引发异常。If the type is not found, the throwIfNotFound parameter specifies whether null is returned or an exception is thrown. 在某些情况下,将引发异常,而不考虑 throwIfNotFound 的值。In some cases, an exception is thrown regardless of the value of throwIfNotFound. 请参见“异常”部分。See the Exceptions section.

异常

调用了类初始值设定项,且该项引发了异常。A class initializer is invoked and throws an exception.

throwIfNotFoundtrue,且找不到该类型。throwIfNotFound is true and the type is not found.

-or- throwIfNotFound 的值为 true,且 typeName 包含无效字符,例如嵌入的制表符。throwIfNotFound is true and typeName contains invalid characters, such as an embedded tab. - 或 --or- throwIfNotFound 的值为 true,且 typeName 为空字符串。throwIfNotFound is true and typeName is an empty string.

-or- throwIfNotFound 的值为 true,且 typeName 表示大小无效的数组类型。throwIfNotFound is true and typeName represents an array type with an invalid size.

-or- typeName 表示 TypedReference 对象数组。typeName represents an array of TypedReference objects.

typeName 不包括程序集名称。typeName does not include the assembly name.

- 或 --or- throwIfNotFoundtrue,且 typeName 包含无效的语法(例如 "MyType[,*,]")。throwIfNotFound is true and typeName contains invalid syntax; for example, "MyType[,*,]".

-or- typeName 表示将指针类型、ByRef 类型或 Void 作为其类型参数之一的泛型类型。typeName represents a generic type that has a pointer type, a ByRef type, or Void as one of its type arguments.

-or- typeName 表示具有错误的类型参数数目的泛型类型。typeName represents a generic type that has an incorrect number of type arguments.

-or- typeName 表示泛型类型,并且其类型参数之一不满足相应类型参数的约束。typeName represents a generic type, and one of its type arguments does not satisfy the constraints for the corresponding type parameter.

throwIfNotFound 的值为 true,且未找到程序集或程序集的某个依赖项。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 valid.

-or-

此程序集使用高于当前所加载版本的公共语言运行时版本编译而成。The assembly was compiled with a later version of the common language runtime than the version that is currently loaded.

注解

如果包含该类型的程序集尚未加载到仅反射上下文中, 则使用ReflectionOnlyGetType方法等效于首先加载仅用于反射的程序集, 然后ReflectionOnlyLoad使用方法, 然后通过调用程序集Assembly.GetType的方法。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. 有关程序集限定名称的信息, 请参见Type.AssemblyQualifiedName属性。For information about assembly-qualified names, see the Type.AssemblyQualifiedName property. 有关指定类型名称的更多详细信息, GetType(String, Boolean, Boolean)请参阅方法重载。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.

throwIfNotFound参数指定当找不到该类型时所发生的情况, 还会取消某些其他异常条件, 如 "异常" 一节中所述。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. 引发一些异常, 而不考虑的值throwIfNotFoundSome exceptions are thrown regardless of the value of throwIfNotFound. 例如, 如果程序集无效, BadImageFormatException throwIfNotFound即使为false, 也会引发。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.

适用于

另请参阅