public void FindOne_ByNameANDParameter(Type type, string methodName, params Type[] parameterTypes) { var search = MethodSearch.Create(); search.SetMethodName(methodName); search.SetParameterTypes(parameterTypes); _output.WriteLine(search.ToSignature().ToString()); var method = type.GetMethods().FindBestMatchingMethodInfo(search); Assert.NotNull(method); _output.WriteLine(method.ToString()); }
public void FindMultiple_ByParameter(Type type, params Type[] parameterTypes) { var search = MethodSearch.Create(); search.SetParameterTypes(parameterTypes); _output.WriteLine(search.ToSignature().ToString()); MethodInfo method = null; try { method = type.GetMethods().FindBestMatchingMethodInfo(search); } catch (MultipleMethodsFoundException e) { Assert.NotNull(e); } Assert.Null(method); }
internal RatedMethodInfo(MethodInfo methodInfo, MethodSearch search) { Search = search; MethodInfo = methodInfo; Rating = MethodSignature.FromMethodInfo(methodInfo).RateAgainst(search, search.Context.SearchFor); }
public static MethodInfo FindBestMatchingMethodInfo(this IEnumerable <RatedMethodInfo> methodInfos, MethodSearch search, bool throwOnError = true) { var possibleMethods = methodInfos .GroupBy(p => p.Rating.ToString()) .OrderBy(result => result.Key).ToList(); if (!possibleMethods.Any()) { if (throwOnError) { throw new MethodNotFoundException(search.Context.MethodName); } return(null); } if (possibleMethods.First().Count() > 1) { if (throwOnError) { throw new MultipleMethodsFoundException(search.Context.MethodName); } return(null); } return(possibleMethods.First().First().MethodInfo); }
public static MethodInfo FindBestMatchingMethodInfo(this IEnumerable <MethodInfo> methodInfos, MethodSearch search, bool throwOnError = true) { return(methodInfos.FindMatchingMethodInfo(search, throwOnError).FindBestMatchingMethodInfo(search, throwOnError)); }
public static IEnumerable <RatedMethodInfo> FindMatchingMethodInfo(this IEnumerable <MethodInfo> methodInfos, MethodSearch search, bool throwOnError = true) { var possibleMethods = methodInfos .Select(m => new RatedMethodInfo(m, search)) .Where(result => !result.Rating.Failed); return(possibleMethods); }