internal static MethodBase GetActualMethod(this MethodReference methodReference) { MethodInfo methodInfo = null; Type[] types = Type.EmptyTypes; Type type = methodReference.DeclaringType.GetActualType(); if (methodReference.Name.Equals(".ctor")) { return(methodReference.GetActualConstructor(type)); } if (methodReference.IsGeneric()) { return(methodReference.GetGenericActualMethod()); } if (!type.ContainsGenericParameters(out types)) { types = methodReference.Parameters .Select(p => p.ParameterType.GetActualType()) .ToArray(); } MethodInfo[] methodInfos = type.GetMember(methodReference.Name, MemberTypes.Method, _flags) .Cast <MethodInfo>() .Where(m => !m.IsGenericMethodDefinition) .ToArray(); if (methodInfos.Length > 1) { methodInfo = Type.DefaultBinder.SelectMethod(_flags, methodInfos, types, null) as MethodInfo; } else { methodInfo = methodInfos[0]; } return(methodInfo); }