MethodBase.GetGenericArguments 方法

定義

回傳一個物件陣列 Type ,代表一般方法的型別參數或一般方法定義的型別參數。

public:
 virtual cli::array <Type ^> ^ GetGenericArguments();
public virtual Type[] GetGenericArguments();
[System.Runtime.InteropServices.ComVisible(true)]
public virtual Type[] GetGenericArguments();
abstract member GetGenericArguments : unit -> Type[]
override this.GetGenericArguments : unit -> Type[]
[<System.Runtime.InteropServices.ComVisible(true)>]
abstract member GetGenericArguments : unit -> Type[]
override this.GetGenericArguments : unit -> Type[]
Public Overridable Function GetGenericArguments () As Type()

傳回

Type[]

一組 Type 物件陣列,代表通用方法的型別參數或一般方法定義的型別參數。 若目前方法不是通用方法,則回傳一個空陣列。

屬性

例外狀況

此方法在衍生類別中不會被覆寫。

備註

回傳陣列的元素依照它們在通用方法型別參數列表中出現的順序排列。

  • 若目前方法為封閉構造方法(即 ContainsGenericParameters 回傳 false屬性),該方法回傳 GetGenericArguments 的陣列包含已指派給通用方法定義中通用型別參數的型別。

  • 如果目前的方法是一個通用方法定義,陣列中包含型別參數。

  • 若目前方法為開放建構方法(即 ContainsGenericParameters 回傳 true屬性),且特定型別被指派給某些型別參數,且包圍一般型別的型別參數被指派給其他型別參數,陣列同時包含型別與型別參數。 利用 IsGenericParameter 這個特性來區分它們。 此情境的示範,請參閱該屬性所提供的 ContainsGenericParameters 程式碼範例。

  • 若目前方法是建構子,回傳的陣列在 .NET 11 及以後版本中為空陣列。 在.NET 10及更早版本中,GetGenericArguments 方法拋出 NotSupportedException

關於通用方法專有項不變條件的列表,請參見性質。IsGenericMethod 關於一般反射中其他術語不變條件的列表,請參見性質。Type.IsGenericType

適用於

另請參閱