private void RunTest()
        {
            var methods = new[] { targetMethod };
            var pool    = methods.AsFuzzyList();

            builder.AddPredicates(pool);
            Assert.IsNotNull(pool.BestMatch());
        }
Esempio n. 2
0
        public bool CanHandle(MethodInfo method)
        {
            if (MethodSpec == null || MethodSpec.MethodBody == null)
            {
                return(false);
            }

            var builder = new PredicateBuilder();

            builder.MatchCovariantParameterTypes = false;
            builder.MatchCovariantReturnType     = false;
            builder.MatchParameterTypes          = true;

            builder.ArgumentTypes.AddRange(MethodSpec.ParameterTypes);
            builder.ReturnType = MethodSpec.ReturnType;

            // Find the method that matches the given name or
            // the alias
            var methodNames = new List <string>();

            methodNames.Add(MethodSpec.MethodName);

            if (MethodSpec.Aliases.Count > 0)
            {
                methodNames.AddRange(MethodSpec.Aliases);
            }

            var found    = false;
            var itemList = new[] { method };

            foreach (var name in methodNames)
            {
                var candidates = itemList.AsFuzzyList();
                builder.MethodName = name;
                builder.AddPredicates(candidates);

                var match = candidates.BestMatch();
                if (match == null)
                {
                    continue;
                }

                found = true;
                break;
            }

            return(found);
        }
        public bool CanHandle(MethodInfo method)
        {
            if (MethodSpec == null || MethodSpec.MethodBody == null)
                return false;

            var builder = new PredicateBuilder();
            builder.MatchCovariantParameterTypes = false;
            builder.MatchCovariantReturnType = false;
            builder.MatchParameterTypes = true;

            builder.ArgumentTypes.AddRange(MethodSpec.ParameterTypes);
            builder.ReturnType = MethodSpec.ReturnType;

            // Find the method that matches the given name or
            // the alias
            var methodNames = new List<string>();
            methodNames.Add(MethodSpec.MethodName);

            if (MethodSpec.Aliases.Count > 0)
                methodNames.AddRange(MethodSpec.Aliases);

            var found = false;
            var itemList = new[] { method };

            foreach (var name in methodNames)
            {                
                var candidates = itemList.AsFuzzyList();
                builder.MethodName = name;
                builder.AddPredicates(candidates);

                var match = candidates.BestMatch();
                if (match == null)
                    continue;

                found = true;
                break;
            }

            return found;
        }