c# - 如果我有继承类类型的 MethodInfo,如何获取接口(interface)的 MethodInfo?

标签 c# .net reflection methodinfo

我有一个类类型的方法的MethodInfo,它是该类实现的接口(interface)定义的一部分。
如何检索类实现的接口(interface)类型上方法的匹配 MethodInfo 对象?

最佳答案

我想我找到了最好的方法:

var methodParameterTypes = classMethod.GetParameters().Select(p => p.ParameterType).ToArray();
MethodInfo interfaceMethodInfo = interfaceType.GetMethod(classMethod.Name, methodParameterTypes);

关于c# - 如果我有继承类类型的 MethodInfo,如何获取接口(interface)的 MethodInfo?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14621451/

相关文章:

c# - linq 另一个列表的有序子集

c# - HttpContext.Current 在异步回调中为 null

c# - 事务性 CloudBlob

java - 类型为 null 的参数应显式转换为 Class<?>[] 以调用 varargs 方法

c# - 在编译时获取非静态方法的 MethodInfo

c# - 如何从 mvc Controller 中的 Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable 获取值

c# - 如何在使用嵌套属性计算值的只读属性上触发 INotifyPropertyChanged

c# - 无法在 SortedList C# 中添加数据

c# - Winforms - 单击控件的 WM_NCHITEST 消息

java - 如何使用父类(super class)构造函数创建子类的实例?