TypeBuilder.SetParent(Type) 方法
定义
设置当前正在构造的类型的基类型。Sets the base type of the type currently under construction.
public:
void SetParent(Type ^ parent);
public void SetParent (Type? parent);
public void SetParent (Type parent);
member this.SetParent : Type -> unit
Public Sub SetParent (parent As Type)
参数
- parent
- Type
新的基类型。The new base type.
例外
该类型是以前使用 CreateType() 创建的。The type was previously created using CreateType().
- 或 --or-
parent 为 null,并且当前实例表示其属性不包括 Abstract 的接口。parent is null, and the current instance represents an interface whose attributes do not include Abstract.
- 或 --or-
对于当前的动态类型,属性 IsGenericType 的值为 true,但属性 IsGenericTypeDefinition 的值为 false。For the current dynamic type, the IsGenericType property is true, but the IsGenericTypeDefinition property is false.
parent 是一个接口。parent is an interface. 此异常条件是 .NET Framework 2.0 版中新增的。This exception condition is new in the .NET Framework version 2.0.
注解
如果 parent 为 null , Object 则将用作基类型。If parent is null, Object is used as the base type.
在 .NET Framework 版本1.0 和1.1 中,如果是接口类型,则不会引发异常 parent ,但在 TypeLoadException CreateType 调用方法时引发。In the .NET Framework versions 1.0 and 1.1, no exception is thrown if parent is an interface type, but a TypeLoadException is thrown when the CreateType method is called.
SetParent方法不检查大多数无效的父类型。The SetParent method does not check for most invalid parent types. 例如,当当前类型具有无参数构造函数时,它不会拒绝没有无参数构造函数的父类型,它不会拒绝密封类型,也不会拒绝该 Delegate 类型。For example, it does not reject a parent type that has no parameterless constructor when the current type has a parameterless constructor, it does not reject sealed types, and it does not reject the Delegate type. 在所有这些情况下,方法均引发异常 CreateType 。In all these cases, exceptions are thrown by the CreateType method.