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 表示找不到類型時擲回 TypeLoadExceptionfalse 表示找不到類型時傳回 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- throwIfNotFoundtrue,而且 typeName 包含無效字元,例如內嵌的定位字元。throwIfNotFound is true and typeName contains invalid characters, such as an embedded tab. -或--or- throwIfNotFoundtrue,而且 typeName 是空字串。throwIfNotFound is true and typeName is an empty string.

-或--or- throwIfNotFoundtrue,而且 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.

throwIfNotFoundtrue,而且找不到組件或組件的其中一個相依性。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.

僅限 .NET Core:不支援此成員。.NET Core only: This member is not supported.

備註

如果包含類型的元件尚未載入到僅限反映的內容中,則使用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參數會指定找不到類型時所發生的情況,也會隱藏特定的例外狀況條件,如 exception 一節中所述。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. 不論的值throwIfNotFound為何,都會擲回一些例外狀況。Some 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.

適用於

另請參閱