Example #1
0
        public void AddChild(ProjectSection section)
        {
            if (section != null)
            {
                _children.Add(section);

                if (_context != null)
                {
                    _context.RegisterSection(section);
                }
            }
        }
        public static IList <ProjectSection> CreateSections(string sourceFile,
                                                            string platform, string configuration, HashSet <string> targetProjectGuids)
        {
            sourceFile = Path.GetFullPath(
                Environment.ExpandEnvironmentVariables(sourceFile));

            string fileExt = Path.GetExtension(sourceFile);

            if (String.IsNullOrEmpty(fileExt))
            {
                return(null);
            }

            ProjectSectionContext context = new ProjectSectionContext();

            context.Platform      = platform;
            context.Configuration = configuration;

            if (targetProjectGuids != null && targetProjectGuids.Count != 0)
            {
                context.RegisterTargets(targetProjectGuids);
            }

            List <ProjectSection> projectSections = new List <ProjectSection>();

            if (fileExt.Equals(".sln", StringComparison.OrdinalIgnoreCase))
            {
                context.SolutionFile = sourceFile;

                IList <ProjectInfo> listProjectInfo = GetProjectInfo(sourceFile);

                if (listProjectInfo != null && listProjectInfo.Count != 0)
                {
                    // Register projects for reference resolution...
                    context.RegisterInfo(listProjectInfo);

                    // If we are documenting all, then add the targets...
                    if (targetProjectGuids == null || targetProjectGuids.Count == 0)
                    {
                        for (int i = 0; i < listProjectInfo.Count; i++)
                        {
                            ProjectInfo projectInfo = listProjectInfo[i];

                            if (projectInfo != null && projectInfo.IsValid)
                            {
                                context.RegisterTarget(projectInfo.ProjectGuid);
                            }
                        }
                    }

                    for (int i = 0; i < listProjectInfo.Count; i++)
                    {
                        ProjectInfo projectInfo = listProjectInfo[i];

                        if (projectInfo != null && projectInfo.IsValid &&
                            context.IsTarget(projectInfo.ProjectGuid))
                        {
                            ProjectSection projectSection = context.GetProjectSection(
                                projectInfo.ProjectGuid);
                            if (projectSection == null)
                            {
                                projectSection = CreateSection(context, projectInfo);
                            }

                            if (projectSection != null)
                            {
                                projectSections.Add(projectSection);
                                context.RegisterSection(projectSection);
                            }
                        }
                    }
                }
            }
            else
            {
                ProjectSection projectSection = CreateSection(context, sourceFile);

                if (projectSection != null)
                {
                    projectSections.Add(projectSection);
                    context.RegisterSection(projectSection);
                }
            }

            return(projectSections);
        }