Beispiel #1
0
        public override SolutionDocumentNode Clone(SolutionDocumentNode newParent)
        {
            var newSolution = new SolutionFile(Path);

            newSolution.Children.AddRange(this.Children.Select(x => x.Clone(newSolution)));
            newSolution.Global = (SolutionGlobal)Global.Clone(newSolution);

            foreach (var keyValue in Projects)
            {
                newSolution.Projects.Add(keyValue.Key, keyValue.Value);
            }

            return(newSolution);
        }
Beispiel #2
0
 protected SolutionSectionContainer(SolutionDocumentNode parent) : base(parent)
 {
 }
Beispiel #3
0
 public abstract SolutionDocumentNode Clone(SolutionDocumentNode newParent);
Beispiel #4
0
 protected SolutionDocumentNode(SolutionDocumentNode parent)
 {
     Parent = parent;
 }
Beispiel #5
0
 public override SolutionDocumentNode Clone(SolutionDocumentNode newParent)
 {
     return(new GlobalNodeMarker((SolutionFile)newParent));
 }
Beispiel #6
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);
        }