示例#1
0
            protected override void OnCollectionChanged(IReadOnlyCollection <IProject> removedItems, IReadOnlyCollection <IProject> addedItems)
            {
                foreach (var project in addedItems)
                {
                    project.ProjectSections.CollectionChanged += solution.OnSolutionSectionCollectionChanged;
                    project.ConfigurationMapping.Changed      += solution.OnProjectConfigurationMappingChanged;
                    solution.OnSolutionSectionCollectionChanged(EmptyList <SolutionSection> .Instance, project.ProjectSections);
                }
                foreach (var project in removedItems)
                {
                    project.ProjectSections.CollectionChanged -= solution.OnSolutionSectionCollectionChanged;
                    project.ConfigurationMapping.Changed      -= solution.OnProjectConfigurationMappingChanged;
                    solution.OnSolutionSectionCollectionChanged(project.ProjectSections, EmptyList <SolutionSection> .Instance);
                }
                // If the startup project was removed, reset that property
                bool startupProjectWasRemoved = removedItems.Contains(solution.startupProject);

                if (startupProjectWasRemoved)
                {
                    solution.startupProject = null;                     // this will force auto-detection on the next property access
                }
                base.OnCollectionChanged(removedItems, addedItems);
                // After the event is raised; dispose any removed projects.
                // Note that this method is only called at the end of a batch update.
                // When moving a project from one folder to another, a batch update
                // must be used to prevent the project from being disposed.
                foreach (var project in removedItems)
                {
                    project.Dispose();
                }
                if (startupProjectWasRemoved || (solution.startupProject == null && addedItems.Contains(solution.AutoDetectStartupProject())))
                {
                    solution.StartupProjectChanged(this, EventArgs.Empty);
                }
            }