コード例 #1
0
        /// <summary>
        /// Maps the single component pattern, to a list of implemented patterns.
        /// </summary>
        /// <param name="pattern">The pattern.</param>
        /// <param name="componentMatches">The component matches.</param>
        /// <returns>The founddesignpatterns model, with the pattern and a list of implementations</returns>
        private FoundDesignPattern MapSingleComponentPattern(DesignPattern pattern, Dictionary <Component, List <ComponentMatch> > componentMatches)
        {
            var foundPattern = new FoundDesignPattern()
            {
                DesignPattern   = pattern,
                Implementations = new List <Dictionary <Component, List <SymbolInformation> > >()
            };

            foreach (var matches in componentMatches.Values.SelectMany(v => v))
            {
                foundPattern.Implementations.Add(
                    new Dictionary <Component, List <SymbolInformation> >()
                {
                    {
                        pattern.Components.Single(),
                        new List <SymbolInformation>()
                        {
                            matches.SymbolInformation
                        }
                    }
                }
                    );
            }

            return(foundPattern);
        }
コード例 #2
0
        /// <summary>
        /// Maps the multiple component pattern.
        /// </summary>
        /// <param name="pattern">The pattern.</param>
        /// <param name="componentMatches">The component matches.</param>
        /// <returns>The founddesignpatterns model, with the pattern and a list of implementations</returns>
        private FoundDesignPattern MapMultipleComponentPattern(DesignPattern pattern, Dictionary <Component, List <ComponentMatch> > componentMatches)
        {
            var foundPattern = new FoundDesignPattern()
            {
                DesignPattern   = pattern,
                Implementations = new List <Dictionary <Component, List <SymbolInformation> > >()
            };

            var graph = new PatternGraph(pattern);
            var implementationCandidates = this.GetPatternImplementations(graph, componentMatches);

            foreach (var implementationCandidate in implementationCandidates)
            {
                var cleanedImplementation = this.RemoveDuplicateComponentMatches(implementationCandidate);

                if (this.MatchComponentCount(pattern, cleanedImplementation))
                {
                    var checkedImplementation = this.MatchImplementationComponentTypes(graph, cleanedImplementation);

                    if (this.MatchComponentCount(pattern, checkedImplementation) && this.ValidComponentOccurrence(checkedImplementation))
                    {
                        foundPattern.Implementations.Add(this.CastDictionary(checkedImplementation));
                    }
                }
            }

            if (foundPattern.Implementations.Count > 0)
            {
                return(foundPattern);
            }

            return(null);
        }
コード例 #3
0
        /// <summary>
        /// Prints the given (and found) pattern. (no indentation)
        /// </summary>
        /// <param name="pattern">The pattern.</param>
        private static void PrintPattern(FoundDesignPattern pattern)
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine($"DesignPattern: {pattern.DesignPattern.Name}");
            Console.ResetColor();

            for (int i = 0; i < pattern.Implementations.Count; i++)
            {
                PrintImplementation(i, pattern.Implementations[i]);
            }
        }