コード例 #1
0
        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());
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 internal RatedMethodInfo(MethodInfo methodInfo, MethodSearch search)
 {
     Search     = search;
     MethodInfo = methodInfo;
     Rating     = MethodSignature.FromMethodInfo(methodInfo).RateAgainst(search, search.Context.SearchFor);
 }
コード例 #4
0
        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);
        }
コード例 #5
0
 public static MethodInfo FindBestMatchingMethodInfo(this IEnumerable <MethodInfo> methodInfos, MethodSearch search, bool throwOnError = true)
 {
     return(methodInfos.FindMatchingMethodInfo(search, throwOnError).FindBestMatchingMethodInfo(search, throwOnError));
 }
コード例 #6
0
        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);
        }