private static ISet <ProjectDetail> ReplaceChildProjectPlaceholders(ProjectDetailRepository other, ISet <ProjectLinkObject> childProjects) { var projectsToRemove = new HashSet <ProjectLinkObject>(); var projectLinksToAdd = new HashSet <ProjectLinkObject>(); var projectsToAddToRepository = new HashSet <ProjectDetail>(); foreach (var childProject in childProjects) { if (childProject.IsOutOfSolution) { string name = Path.GetFileNameWithoutExtension(childProject.FullPath); var possibleProjects = other.GetByName(name); if (possibleProjects.Count == 0) { } else if (possibleProjects.Count == 1) { _ = projectsToRemove.Add(childProject); _ = projectsToAddToRepository.Add(possibleProjects.First()); _ = projectLinksToAdd.Add(new ProjectLinkObject(possibleProjects.First())); } else { throw new ArgumentException(string.Format("There is more than one possible project '{0}'", name)); } } } childProjects.ExceptWith(projectsToRemove); childProjects.UnionWith(projectLinksToAdd); return(projectsToAddToRepository); }
private static void OptimizeCollection(ProjectDetailRepository projectRepository, ISet <ProjectLinkObject> references) { var projectsToRemove = new HashSet <ProjectLinkObject>(); var projectsToAdd = new HashSet <ProjectLinkObject>(); foreach (var reference in references) { if (reference.IsOutOfSolution) { string name = Path.GetFileNameWithoutExtension(reference.FullPath); var projects = projectRepository.GetByName(name); if (projects.Count == 0) { // Just leave it as is } else if (projects.Count == 1) { var projectLinkObject = new ProjectLinkObject(projects.First()); _ = projectsToRemove.Add(reference); _ = projectsToAdd.Add(projectLinkObject); } else { throw new ArgumentException(string.Format("More than one project has the same name '{0}'", name)); } } } references.ExceptWith(projectsToRemove); references.UnionWith(projectsToAdd); }