Module.GetMethod 方法

定义

返回具有指定条件的方法。

重载

GetMethod(String)

返回具有指定名称的方法。

GetMethod(String, Type[])

返回具有指定名称和参数类型的方法。

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

返回具有指定名称、绑定信息、调用约定和参数类型及修饰符的方法。

GetMethod(String)

Source:
Module.cs
Source:
Module.cs
Source:
Module.cs

返回具有指定名称的方法。

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

参数

name
String

方法名称。

返回

具有指定名称的 MethodInfo 对象,如果该方法不存在则为 null

例外

namenull

适用于

.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[])

Source:
Module.cs
Source:
Module.cs
Source:
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,或 types (i) 为 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, BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[])

Source:
Module.cs
Source:
Module.cs
Source:
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,或 types (i) 为 null

另请参阅

适用于

.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