Module.GetMethod 方法

定義

傳回具有指定準則的方法。

多載

GetMethod(String)

傳回具有指定名稱的方法。

GetMethod(String, Type[])

傳回具有指定名稱和參數型別的方法。

GetMethod(String, BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[])

傳回具有指定名稱、系結資訊、呼叫慣例和參數類型和修飾詞的方法。

GetMethod(String)

來源:
Module.cs
來源:
Module.cs
來源:
Module.cs

傳回具有指定名稱的方法。

C#
public System.Reflection.MethodInfo? GetMethod (string name);
C#
public System.Reflection.MethodInfo GetMethod (string name);

參數

name
String

方法名稱。

傳回

具有指定名稱的 MethodInfo 物件,如果方法不存在,則為 null

例外狀況

name null

適用於

.NET 9 和其他版本
產品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.5, 1.6, 2.0, 2.1

GetMethod(String, Type[])

來源:
Module.cs
來源:
Module.cs
來源:
Module.cs

傳回具有指定名稱和參數型別的方法。

C#
public System.Reflection.MethodInfo? GetMethod (string name, Type[] types);
C#
public System.Reflection.MethodInfo GetMethod (string name, Type[] types);

參數

name
String

方法名稱。

types
Type[]

要搜尋的參數類型。

傳回

根據指定的準則 MethodInfo 物件,如果方法不存在,則為 null

例外狀況

namenulltypesnull,或 typesnull

適用於

.NET 9 和其他版本
產品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.5, 1.6, 2.0, 2.1

GetMethod(String, BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[])

來源:
Module.cs
來源:
Module.cs
來源:
Module.cs

傳回具有指定名稱、系結資訊、呼叫慣例和參數類型和修飾詞的方法。

C#
public System.Reflection.MethodInfo? GetMethod (string name, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder? binder, System.Reflection.CallingConventions callConvention, Type[] types, System.Reflection.ParameterModifier[]? modifiers);
C#
public System.Reflection.MethodInfo GetMethod (string name, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Reflection.CallingConventions callConvention, Type[] types, System.Reflection.ParameterModifier[] modifiers);

參數

name
String

方法名稱。

bindingAttr
BindingFlags

用來控制搜尋的其中一個 BindingFlags 位旗標。

binder
Binder

實作 Binder的物件,包含與這個方法相關的屬性。

callConvention
CallingConventions

方法的呼叫慣例。

types
Type[]

要搜尋的參數類型。

modifiers
ParameterModifier[]

參數修飾詞陣列,用來讓系結使用已修改型別的參數簽章。

傳回

根據指定的準則 MethodInfo 物件,如果方法不存在,則為 null

例外狀況

namenulltypesnull,或 typesnull

另請參閱

適用於

.NET 9 和其他版本
產品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1