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- parentnull,而且目前的執行個體代表其屬性不包含 Abstract 的介面。parent is null, and the current instance represents an interface whose attributes do not include Abstract.

-或--or- 目前動態類型的 IsGenericType 屬性為 true,但 IsGenericTypeDefinition 屬性為 falseFor 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.

備註

如果 parentnullObject 則會當做基底類型使用。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. 在這些情況下,方法會擲回例外狀況 CreateTypeIn all these cases, exceptions are thrown by the CreateType method.

適用於