コード例 #1
0
 public override void AddChild(SolutionDocLine line)
 => throw new NotSupportedException();
コード例 #2
0
 public virtual void AddChild(SolutionDocLine line)
 {
     Children.Add(new SolutionDocumentTrivialNode(this, line));
 }
コード例 #3
0
        public static SolutionFile Parse(string path, string[] contentLines)
        {
            var solutionFile             = new SolutionFile(path);
            SolutionDocumentNode current = solutionFile;

            var isProjectMarkerAdded = false;

            foreach (var line in contentLines)
            {
                var parsedLine = SolutionDocLine.ParseLine(line);
                switch (parsedLine.Type)
                {
                case SlnDocLineType.ProjectBegin:
                {
                    if (!(current is SolutionFile))
                    {
                        throw new InvalidOperationException("Project must be located under Solution");
                    }
                    var sln  = current as SolutionFile;
                    var proj = new SolutionProject(current, parsedLine);
                    current = proj;
                    if (sln.Projects.ContainsKey(proj.Guid))
                    {
                        // already exists
                        continue;
                    }
                    sln.Projects.Add(proj.Guid, proj);

                    // The project is first item of projects.
                    if (sln.Projects.Count == 1)
                    {
                        sln.Children.Add(new ProjectsNodeMarker(sln));
                        isProjectMarkerAdded = true;
                    }
                }
                break;

                case SlnDocLineType.ProjectSectionBegin:
                {
                    if (!(current is SolutionProject))
                    {
                        throw new InvalidOperationException("ProjectSection must be located under Project");
                    }
                    var proj        = current as SolutionProject;
                    var projSection = new SolutionProjectSection(current, parsedLine);
                    current = projSection;
                    if (proj.Sections.ContainsKey((projSection.Category, projSection.Value)))
                    {
                        // already exists
                        continue;
                    }
                    proj.Sections.Add((projSection.Category, projSection.Value), projSection);
                }
                break;

                case SlnDocLineType.GlobalBegin:
                {
                    if (!(current is SolutionFile))
                    {
                        throw new InvalidOperationException("Global must be located under Solution");
                    }
                    var sln = current as SolutionFile;
                    sln.Global = new SolutionGlobal(current);

                    if (!isProjectMarkerAdded)
                    {
                        // `Project` is always puts before `Global`.
                        sln.Children.Add(new ProjectsNodeMarker(sln));
                        isProjectMarkerAdded = true;
                    }
                    sln.Children.Add(new GlobalNodeMarker(sln));

                    current = sln.Global;
                }
                break;

                case SlnDocLineType.GlobalSectionBegin:
                {
                    if (!(current is SolutionGlobal))
                    {
                        throw new InvalidOperationException("GlobalSection must be located under Global");
                    }
                    var global        = current as SolutionGlobal;
                    var globalSection = new SolutionGlobalSection(current, parsedLine);
                    if (global.Sections.ContainsKey((globalSection.Category, globalSection.Value)))
                    {
                        // already exists
                        continue;
                    }
                    global.Sections.Add((globalSection.Category, globalSection.Value), globalSection);
                    current = globalSection;
                }
                break;

                case SlnDocLineType.GlobalEnd:
                case SlnDocLineType.ProjectEnd:
                case SlnDocLineType.ProjectSectionEnd:
                case SlnDocLineType.GlobalSectionEnd:
                    current = current.Parent;
                    break;

                default:
                    current.AddChild(parsedLine);
                    break;
                }
            }
            return(solutionFile);
        }