ModuleBuilder.GetType 方法

定义

获取模块中定义的命名类型。

重载

GetType(String)

获取模块中定义的命名类型。

GetType(String, Boolean)

获取模块中定义的命名类型,可以忽略类型名称的大小写。

GetType(String, Boolean, Boolean)

获取模块中定义的命名类型,可以忽略类型名称的大小写。 如果未找到该类型,则可选择引发异常。

GetType(String)

获取模块中定义的命名类型。

public:
 override Type ^ GetType(System::String ^ className);
public override Type? GetType (string className);
public override Type GetType (string className);
[System.Runtime.InteropServices.ComVisible(true)]
public override Type GetType (string className);
override this.GetType : string -> Type
[<System.Runtime.InteropServices.ComVisible(true)>]
override this.GetType : string -> Type
Public Overrides Function GetType (className As String) As Type

参数

className
String

要获取的 Type 的名称。

返回

Type

如果已在此模块中定义了请求的类型,则为此类型;否则为 null

属性

例外

className 的长度为零或大于 1023。

classNamenull

请求的 Type 是非公共的,且调用方没有将非公共对象反射到当前程序集外部的 ReflectionPermission

调用了类初始值设定项,且该项引发了异常。

加载 Type 时遇到错误。

注解

请勿使用此方法生成数组类型、指针类型或 byref 类型。 请 TypeBuilder.MakeArrayType 改为 TypeBuilder.MakePointerType 使用 、 和 TypeBuilder.MakeByRefType 方法。

备注

从 .NET Framework 2.0 Service Pack 1 开始,此成员不再需要 ReflectionPermissionReflectionPermissionFlag.ReflectionEmit 标志。 (反射发出.) 中的安全问题 若要使用此功能,应用程序应面向 .NET Framework 3.5 或更高版本。

适用于

GetType(String, Boolean)

获取模块中定义的命名类型,可以忽略类型名称的大小写。

public:
 override Type ^ GetType(System::String ^ className, bool ignoreCase);
public override Type? GetType (string className, bool ignoreCase);
public override Type GetType (string className, bool ignoreCase);
[System.Runtime.InteropServices.ComVisible(true)]
public override Type GetType (string className, bool ignoreCase);
override this.GetType : string * bool -> Type
[<System.Runtime.InteropServices.ComVisible(true)>]
override this.GetType : string * bool -> Type
Public Overrides Function GetType (className As String, ignoreCase As Boolean) As Type

参数

className
String

要获取的 Type 的名称。

ignoreCase
Boolean

如果为 true,则搜索不区分大小写。 如果为 false,则搜索区分大小写。

返回

Type

如果已在此模块中定义了请求的类型,则为此类型;否则为 null

属性

例外

className 的长度为零或大于 1023。

classNamenull

请求的 Type 是非公共的,且调用方没有将非公共对象反射到当前程序集外部的 ReflectionPermission

调用了类初始值设定项,且该项引发了异常。

注解

请勿使用此方法生成数组类型、指针类型或 byref 类型。 请 TypeBuilder.MakeArrayType 改为 TypeBuilder.MakePointerType 使用 、 和 TypeBuilder.MakeByRefType 方法。

备注

从 .NET Framework 2.0 Service Pack 1 开始,此成员不再需要 ReflectionPermissionReflectionPermissionFlag.ReflectionEmit 标志。 (反射发出.) 中的安全问题 若要使用此功能,应用程序应面向 .NET Framework 3.5 或更高版本。

适用于

GetType(String, Boolean, Boolean)

获取模块中定义的命名类型,可以忽略类型名称的大小写。 如果未找到该类型,则可选择引发异常。

public:
 override Type ^ GetType(System::String ^ className, bool throwOnError, bool ignoreCase);
public override Type? GetType (string className, bool throwOnError, bool ignoreCase);
public override Type GetType (string className, bool throwOnError, bool ignoreCase);
[System.Runtime.InteropServices.ComVisible(true)]
public override Type GetType (string className, bool throwOnError, bool ignoreCase);
override this.GetType : string * bool * bool -> Type
[<System.Runtime.InteropServices.ComVisible(true)>]
override this.GetType : string * bool * bool -> Type
Public Overrides Function GetType (className As String, throwOnError As Boolean, ignoreCase As Boolean) As Type

参数

className
String

要获取的 Type 的名称。

throwOnError
Boolean

如果为 true,则在找不到该类型时引发异常;如果为 false,则返回 null

ignoreCase
Boolean

如果为 true,则搜索不区分大小写。 如果为 false,则搜索区分大小写。

返回

Type

如果指定类型已在此模块中声明,则为该类型;否则为 null

属性

例外

className 的长度为零或大于 1023。

classNamenull

请求的 Type 是非公共的,且调用方没有将非公共对象反射到当前程序集外部的 ReflectionPermission

调用了类初始值设定项,且该项引发了异常。

throwOnErrortrue,未找到指定的类型。

注解

throwOnError参数仅影响找不到类型时发生的情况。 它不会影响可能引发的任何其他异常。 具体而言,如果找到类型但无法加载 ,则即使 TypeLoadException 为 ,也可以 throwOnError 引发 false

请勿使用此方法生成数组类型、指针类型或 byref 类型。 请 TypeBuilder.MakeArrayType 改为 TypeBuilder.MakePointerType 使用 、 和 TypeBuilder.MakeByRefType 方法。

备注

从 .NET Framework 2.0 Service Pack 1 开始,此成员不再需要 ReflectionPermissionReflectionPermissionFlag.ReflectionEmit 标志。 (反射发出.) 中的安全问题 若要使用此功能,应用程序应面向 .NET Framework 3.5 或更高版本。

适用于