Esempio n. 1
0
        public virtual InvocationChain GetChain(ScenarioContext context, string line)
        {
            DebugTrace.Trace("Interpreting", line);
            var chains = (GetSelectedChains(context, line) ?? new InvocationChain[0]).ToArray();

            if (!chains.Any())
            {
                DebugTrace.Trace(GetType().Name, "no match: " + line);
            }

            if (chains.Count() > 1)
            {
                var chain = _resolver.ResolveMatch(line, chains);
                Notify(chain);
                return(chain);
            }

            if (chains.Any())
            {
                var chain = chains.FirstOrDefault();
                Notify(chain);
                return(chain);
            }

            return(null);
        }
Esempio n. 2
0
        public IEnumerable <InvocationChain> GetChains(string line)
        {
            DebugTrace.Trace(GetType().Name, "Interpreting '" + line + "' with type:" + _contextType.WrappedType.Name);

            var partialMatches = new List <PartialMatch>();

            foreach (var matcher in _contextType.MemberMatchers)
            {
                foreach (var currentMatch in matcher.GetMatches(line) ?? new NameMatch[0])
                {
                    if (currentMatch is ExactMatch)
                    {
                        DebugTrace.Trace(GetType().Name, "Exact match");

                        yield return(new InvocationChain
                        {
                            Invocations = new[] { BuildInvocation(matcher.MemberInfo, currentMatch) }
                        });
                    }
                    else if (currentMatch is PartialMatch)
                    {
                        DebugTrace.Trace(GetType().Name, "Partial match -" + currentMatch.MatchedText);
                        partialMatches.Add((PartialMatch)currentMatch);
                    }
                }
            }

            var partialMatchChains = GetPartialMatchChains(line, partialMatches);

            foreach (var partialMatchChain in partialMatchChains)
            {
                yield return(partialMatchChain);
            }
        }
Esempio n. 3
0
        public IEnumerable <IMemberMatcher> GetMatchers(Type type)
        {
            foreach (var methodInfo in _extensionMethodHandler.GetExtensionMethodsFor(type))
            {
                DebugTrace.Trace(GetType().Name, "Added extension method matcher: " + methodInfo.Name);

                yield return(new MethodNameMatcher(methodInfo));
            }
        }
Esempio n. 4
0
        public IEnumerable <IMemberMatcher> GetMatchers(Type type)
        {
            foreach (MemberInfo member in GetMembersWeCareAbout(type))
            {
                var reflectionMatcher = GetMemberMatcher(member);

                if (reflectionMatcher != null)
                {
                    DebugTrace.Trace(GetType().Name, "Added reflection matcher: " + member.Name);

                    yield return(reflectionMatcher);
                }
            }
        }
Esempio n. 5
0
        public IEnumerable <IMemberMatcher> GetMatchers(Type type)
        {
            foreach (MemberInfo member in _memberReader.GetMembers(type, BindingFlags.Instance | BindingFlags.Public))
            {
                var regexAttrs = member.GetCustomAttributes(true).Where(x => x.GetType().Name == typeof(ContextRegexAttribute).Name);

                foreach (var regexAttr in regexAttrs)
                {
                    var pattern = (string)regexAttr.ReflectionGet("Pattern");

                    DebugTrace.Trace(GetType().Name,
                                     "Added regex matcher: " + member.Name + ", \"" + pattern + "\"");

                    yield return(new RegexMatcher(pattern, member));
                }
            }
        }
Esempio n. 6
0
        private void AddExtensionMethods(Type type)
        {
            if (AlreadyAddedType(type))
            {
                return;
            }
            _addedTypes.Add(type);

            var publicStaticMethods = type.GetMethods(BindingFlags.Public | BindingFlags.Static);
            var extensionMethods    =
                publicStaticMethods.Where(methodInfo => methodInfo.IsStatic & methodInfo.IsDefined(typeof(ExtensionAttribute), true));

            foreach (var methodInfo in extensionMethods)
            {
                DebugTrace.Trace("ExtensionMethodHandler", "Adding extension method: " + type.Name + "." + methodInfo.Name);
                _allExtensionMethods.Add(methodInfo);
            }
        }