Search code examples
c#.netreflectionmethodinfo

How to get MethodInfo of interface, if i have MethodInfo of inherited class type?


I have the MethodInfo of a method on a class type that is part of an interface definition that that class implements.
How can I retrieve the matching MethodInfo object of the method on the interface type that the class implements ?


Solution

  • I think i found the best way to do this :

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