public override MemberInfo Translate(MemberInfo member) { string[] names = _alternateNames.Union(new[] { member.Name }).ToArray(); IEnumerable <MemberInfo> members = TargetType.GetAllMembers().Where(m => names.Contains(m.Name)); if (!members.Any()) { Verifier.FailMemberNotFound(TargetType, names); } // Multiple MethodBase members may have the same name and only differ in argument list if (member is MethodBase methodBase1) { foreach (var methodBase2 in members.OfType <MethodBase>()) { var parameterTypes1 = methodBase1.GetParameters().Select(p => p.ParameterType); var parameterTypes2 = methodBase2.GetParameters().Select(p => p.ParameterType); if (parameterTypes1.SequenceEqual(parameterTypes2)) { return(methodBase2); } } throw new NotImplementedException(); } return(members.First()); }
public override MemberInfo Translate(MemberInfo member) { IEnumerable <MemberInfo> members = TargetType.GetAllMembers().Where(m => m.Name == member.Name); if (!members.Any()) { Verifier.FailMemberNotFound(TargetType, new[] { member.Name }); } // Multiple MethodBase members may have the same name and only differ in argument list if (member is MethodBase methodBase1) { foreach (var methodBase2 in members.OfType <MethodBase>()) { // TODO Try to do this somewhat simpler var methodBase3 = methodBase2; if (methodBase2.IsGenericMethod && !methodBase2.IsConstructedGenericMethod) { methodBase3 = ((MethodInfo)methodBase2).MakeGenericMethod(methodBase1.GetGenericArguments()); } var parameterTypes1 = methodBase1.GetParameters().Select(p => Service.TranslateType(p.ParameterType)); var parameterTypes2 = methodBase3.GetParameters().Select(p => p.ParameterType); if (parameterTypes1.SequenceEqual(parameterTypes2)) { return(methodBase2); } } // Fail if no matching method is found if (methodBase1 is MethodInfo methodInfo) { Verifier.FailMethodNotFound(TargetType, methodInfo); } if (methodBase1 is ConstructorInfo constructorInfo) { Verifier.FailConstructorNotFound(TargetType, constructorInfo); } } return(members.First()); }