我有一个接口(interface)方法的MethodInfo
和一个实现的类的Type
界面。
我想找到实现接口(interface)方法的类方法的MethodInfo
简单的 method.GetBaseDefinition()
不适用于接口(interface)方法。
按名称查找也不起作用,因为当显式实现接口(interface)方法时,它可以有任何名称(是的,不是在 C# 中)。
那么什么是正确的方法来覆盖所有的可能性?
最佳答案
好的,我找到了一个方法,使用GetInterfaceMap .
var map = targetType.GetInterfaceMap(interfaceMethod.DeclaringType);
var index = Array.IndexOf(map.InterfaceMethods, interfaceMethod);
if (index == -1)
{
//this should literally be impossible
}
return map.TargetMethods[index];
关于c# - 如何获取接口(interface)方法的MethodInfo,实现了类方法的MethodInfo?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1113635/