Пример #1
0
        private static Class GetClassByFullName(Solution solution, string type)
        {
            var typeReference = solution.Projects.SelectMany(x => x.Namespaces).ToList().SelectMany(x => x.Classes)
                                .ToList().FirstOrDefault(x => x.FullName.Equals(type));

            return(typeReference);
        }
Пример #2
0
        private void AddReferencesBetweenMethodsAndClasses(Solution solution)
        {
            foreach (var keyValue in _methodToClassMapping)
            {
                var method            = keyValue.Key;
                var referencedClasses = keyValue.Value;

                var parentClass     = method.Parent as Class;
                var parentNamespace = parentClass?.Parent as Namespace;
                if (parentNamespace == null)
                {
                    continue;
                }

                foreach (var fullClassName in referencedClasses)
                {
                    var @class = GetClassByFullName(solution, fullClassName);
                    if (@class == null)
                    {
                        continue;
                    }

                    method.OutReferences.Add(@class);
                    @class.InReferences.Add(method);
                }
            }
        }
Пример #3
0
 private void MapReferences(Solution solution)
 {
     // TODO: Handle all parallel after code above to improve performance
     AddReferencesBetweenProjects(solution);
     AddReferencesBetweenNamespaces(solution);
     AddReferencesBetweenClasses(solution);
     AddReferencesBetweenProperties(solution);
     AddReferencesBetweenFields(solution);
     AddReferencesBetweenMethodsAndClasses(solution);
     AddReferencesBetweenMethods(solution);
 }
Пример #4
0
        private void AddReferencesBetweenFields(Solution solution)
        {
            foreach (var keyValue in _fieldToTypeMapping)
            {
                var field = keyValue.Key;
                var type  = keyValue.Value;

                var @class = GetClassByFullName(solution, type);

                if (@class == null)
                {
                    continue;
                }

                field.OutReferences.Add(@class);
                @class.InReferences.Add(field);
            }
        }
Пример #5
0
        private void AddReferencesBetweenProperties(Solution solution)
        {
            foreach (var keyValue in _propertyToTypeMapping)
            {
                var property = keyValue.Key;
                var type     = keyValue.Value;

                var @class = GetClassByFullName(solution, type);

                if (@class == null)
                {
                    continue;
                }

                property.OutReferences.Add(@class);
                @class.InReferences.Add(property);
            }
        }
Пример #6
0
        private void AddReferencesBetweenProjects(Solution solution)
        {
            foreach (var keyValue in _projectToProjectMapping)
            {
                var project    = keyValue.Key;
                var references = keyValue.Value;
                foreach (var reference in references)
                {
                    var projectReference = solution.Projects.FirstOrDefault(x => x.ProjectId.Equals(reference));
                    if (projectReference == null)
                    {
                        continue;
                    }

                    project.OutReferences.Add(projectReference);
                    projectReference.InReferences.Add(project);
                }
            }
        }
Пример #7
0
        private void AddReferencesBetweenClasses(Solution solution)
        {
            foreach (var keyValue in _classToClassMapping)
            {
                var @class     = keyValue.Key;
                var references = keyValue.Value;
                foreach (var referenceFullName in references)
                {
                    var classReference = GetClassByFullName(solution, referenceFullName);

                    if (classReference == null)
                    {
                        continue;
                    }

                    @class.OutReferences.Add(classReference);
                    classReference.InReferences.Add(@class);
                }
            }
        }
Пример #8
0
        /// <summary>
        ///     Generates a new dependency solution based on opened solution
        /// </summary>
        /// <returns></returns>
        public async Task <Solution> GenerateDependencyTree()
        {
            var solution = new Solution();

            ResetTmpStorage();

            // TODO: Handle all parallel to improve performance
            foreach (var msProject in (await GetCurrentSolution()).Projects)
            {
                var referencedProjectIds = msProject.ProjectReferences.Select(x => x.ProjectId).ToList();
                var project = new Project(Guid.NewGuid(), msProject.Id, msProject.Name);
                _projectToProjectMapping.Add(project, referencedProjectIds);
                await AddDocuments(msProject, project);

                solution.Projects.Add(project);
            }

            MapReferences(solution);

            return(solution);
        }
Пример #9
0
        private void AddReferencesBetweenNamespaces(Solution solution)
        {
            foreach (var keyValue in _namespaceToNamespaceMapping)
            {
                var ns         = keyValue.Key;
                var references = keyValue.Value;
                foreach (var reference in references)
                {
                    // TODO: This does not work if a namespace is defined in multiple projects
                    // At this case we need to check the referenced classes
                    var referenceNamespace = solution.Projects.SelectMany(x => x.Namespaces).ToList()
                                             .FirstOrDefault(x => x.Name.Equals(reference));

                    if (referenceNamespace == null)
                    {
                        continue;
                    }

                    ns.OutReferences.Add(referenceNamespace);
                    referenceNamespace.InReferences.Add(ns);
                }
            }
        }
Пример #10
0
        private void AddReferencesBetweenMethods(Solution solution)
        {
            foreach (var keyValue in _methodToMethodMapping)
            {
                var method            = keyValue.Key;
                var referencedMethods = keyValue.Value;

                foreach (var fullMethodName in referencedMethods)
                {
                    var classMethod = solution.Projects.SelectMany(x => x.Namespaces).ToList()
                                      .SelectMany(x => x.Classes).ToList()
                                      .SelectMany(x => x.Methods).ToList()
                                      .FirstOrDefault(x => x.FullName.Equals(fullMethodName));

                    if (classMethod == null)
                    {
                        continue;
                    }

                    method.OutReferences.Add(classMethod);
                    classMethod.InReferences.Add(method);
                }
            }
        }