Beispiel #1
0
        public SlnFileBrowser(SlnFileData data)
        {
            Data = data;

            _projectInfos    = new Lazy <Dictionary <string, SlnFileProject> >(LoadProjectInfos);
            _solutionFolders = new Lazy <HashSet <string> >(LoadSolutionFolders);
            _nestedProjects  = new Lazy <Dictionary <string, string> >(LoadNestedProjects);
        }
Beispiel #2
0
        public static List <string> RenderLines(SlnFileData data)
        {
            var list = new List <string>();

            list.AddRange(RenderHeader(data.Header));
            list.AddRange(data.Projects.SelectMany(RenderProject));
            list.Add("Global");
            list.AddRange(data.GlobalSections.SelectMany(RenderGlobalSection));
            list.Add("EndGlobal");
            return(list);
        }
Beispiel #3
0
 public static SlnFileBrowser Browse(this SlnFileData data) => new(data);
Beispiel #4
0
 public static void WriteToFile(SlnFileData data, string path) => File.WriteAllLines(path, RenderLines(data));
Beispiel #5
0
        public static SlnFileData ParseLines(IEnumerable <string> lines)
        {
            var data = new SlnFileData();

            SlnFileProject?currentProject        = null;
            SlnFileSection?currentProjectSection = null;
            SlnFileSection?currentGlobalSection  = null;

            foreach (var line in lines)
            {
                if (String.IsNullOrEmpty(line))
                {
                    continue;
                }

                if (currentProject != null)
                {
                    if (currentProjectSection != null)
                    {
                        if (ParseProjectSectionEnd(line))
                        {
                            currentProject.ProjectSections.Add(currentProjectSection);
                            currentProjectSection = null;
                            continue;
                        }

                        var property = ParseSectionPropertyLine(line);
                        currentProjectSection.Properties.Add(property);
                        continue;
                    }

                    if (ParseProjectSectionBegin(line, out var projSec))
                    {
                        currentProjectSection = projSec;
                        continue;
                    }

                    if (ParseProjectEnd(line))
                    {
                        data.Projects.Add(currentProject);
                        currentProject = null;
                        continue;
                    }
                }

                if (currentGlobalSection != null)
                {
                    if (ParseGlobalSectionEnd(line))
                    {
                        data.GlobalSections.Add(currentGlobalSection);
                        currentGlobalSection = null;
                        continue;
                    }

                    var property = ParseSectionPropertyLine(line);
                    currentGlobalSection.Properties.Add(property);
                    continue;
                }

                if (ParseHeaderLine(data.Header, line))
                {
                    continue;
                }

                if (ParseProjectBegin(line, out var proj))
                {
                    currentProject = proj;
                    continue;
                }

                if (ParseGlobal(line))
                {
                    continue;
                }

                if (ParseGlobalSectionBegin(line, out var globSec))
                {
                    currentGlobalSection = globSec;
                    continue;
                }

                throw new InvalidOperationException($"Unexpected solution line: {line}");
            }

            return(data);
        }