/// <summary> /// Resolves a given <paramref name="methodInfo"/> to the <see cref="MethodInfo"/> representing the actual implementation. /// </summary> /// <remarks> /// see article <a href="http://weblog.ikvm.net/CommentView.aspx?guid=7356a87f-e5d7-4723-ae49-b263ab9e40ae">How To Get an Explicit Interface Implementation Method</a>. /// </remarks> /// <param name="methodInfo">a <see cref="MethodInfo"/></param> /// <param name="implementingType">the type to lookup</param> /// <returns>the <see cref="MethodInfo"/> representing the actual implementation method of the specified <paramref name="methodInfo"/></returns> public static MethodInfo MapInterfaceMethodToImplementationIfNecessary(MethodInfo methodInfo, System.Type implementingType) { AssertUtils.ArgumentNotNull(methodInfo, "methodInfo"); AssertUtils.ArgumentNotNull(implementingType, "implementingType"); AssertUtils.IsTrue(methodInfo.DeclaringType.IsAssignableFrom(implementingType), "methodInfo and implementingType are unrelated"); MethodInfo concreteMethodInfo = methodInfo; if (methodInfo.DeclaringType.IsInterface) { InterfaceMapping interfaceMapping = implementingType.GetInterfaceMap(methodInfo.DeclaringType); int methodIndex = Array.IndexOf(interfaceMapping.InterfaceMethods, methodInfo); concreteMethodInfo = interfaceMapping.TargetMethods[methodIndex]; } return concreteMethodInfo; }
private static MethodInfo[] GetIntroducedMethods(System.Type type, ref string[] methodAttributes) { BindingFlags bindingAttr = BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly; MethodInfo[] methods = type.GetMethods(bindingAttr); if (!type.IsInterface) { methodAttributes = new string[methods.Length]; FindMethodAttributes(type, methods, ref methodAttributes, bindingAttr); ArrayList list = new ArrayList(); foreach (System.Type type2 in type.GetInterfaces()) { foreach (MethodInfo info in type.GetInterfaceMap(type2).TargetMethods) { if (!info.IsPublic && (type.GetMethod(info.Name, bindingAttr | BindingFlags.NonPublic) != null)) { list.Add(info); } } } MethodInfo[] infoArray2 = null; if (list.Count > 0) { infoArray2 = new MethodInfo[methods.Length + list.Count]; for (int i = 0; i < methods.Length; i++) { infoArray2[i] = methods[i]; } for (int j = 0; j < list.Count; j++) { infoArray2[methods.Length + j] = (MethodInfo) list[j]; } return infoArray2; } } return methods; }