How to get MethodInfo of interface method, having implementing MethodInfo of class method?

后端 未结 1 1241
猫巷女王i
猫巷女王i 2020-11-30 09:28

I have a MethodInfo of an interface method and Type of a class that implements the interface. I want to find the M

相关标签:
1条回答
  • 2020-11-30 10:16

    OK, I found a way, using 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];
    
    0 讨论(0)
提交回复
热议问题