Esempio n. 1
0
        private static void SerializeGlobal(TabinatedWriter writer, ISerializableSolutionFileGlobalSection serializableGlobalSection)
        {
            var globalSectionLine = $"GlobalSection({serializableGlobalSection.Name}) = {SolutionUtilities.ToStringStandard(serializableGlobalSection.PreOrPostSolution)}";

            writer.WriteLine(globalSectionLine);

            writer.IncreaseTabination();
            foreach (var line in serializableGlobalSection.ContentLines)
            {
                writer.WriteLine(line);
            }
            writer.DecreaseTabination();

            writer.WriteLine("EndGlobalSection");
        }
Esempio n. 2
0
        private static void SerializeGlobals(TextWriter writer, SolutionFile solutionFile)
        {
            var tabinatedWriter = new TabinatedWriter(writer);

            tabinatedWriter.WriteLine("Global");

            tabinatedWriter.IncreaseTabination();

            var globalSections        = new List <ISolutionFileGlobalSection>(solutionFile.GlobalSections);
            var globalSectionsInOrder = new List <ISolutionFileGlobalSection>();

            // SolutionConfigurationPlatforms.
            var solutionConfigurationPlatforms = globalSections.GetSolutionConfigurationPlatformsGlobalSection(); // Must have.

            globalSectionsInOrder.Add(solutionConfigurationPlatforms);
            globalSections.Remove(solutionConfigurationPlatforms);

            // ProjectConfigurationPlatforms.
            var hasProjectConfigurationPlatforms = globalSections.HasProjectConfigurationPlatformsGlobalSection(out var projectConfigurationPlatforms); // Can have.

            if (hasProjectConfigurationPlatforms)
            {
                globalSectionsInOrder.Add(projectConfigurationPlatforms);
                globalSections.Remove(projectConfigurationPlatforms);
            }

            // Solution properties.
            var solutionProperties = globalSections.GetGlobalSectionByName <GeneralSolutionFileGlobalSection>(Constants.SolutionPropertiesSolutionGlobalSectionName); // Must have.

            globalSectionsInOrder.Add(solutionProperties);
            globalSections.Remove(solutionProperties);

            // Nested projects.
            var hasNestedProjects = globalSections.HasNestedProjectsGlobalSection(out var nestedProjects); // Can have.

            if (hasNestedProjects)
            {
                globalSectionsInOrder.Add(nestedProjects);
                globalSections.Remove(nestedProjects);
            }

            // Extensibility globals.
            var hasExtensibilityGlobals = globalSections.HasGlobalSectionByName <GeneralSolutionFileGlobalSection>(Constants.ExtensibilityGlobalsSolutionGlobalSectionName, out var extensibilityGlobals); // Can have.

            if (hasExtensibilityGlobals)
            {
                globalSectionsInOrder.Add(extensibilityGlobals);
                globalSections.Remove(extensibilityGlobals);
            }

            // All others that remain.
            globalSectionsInOrder.AddRange(globalSections);

            foreach (var globalSection in globalSectionsInOrder)
            {
                if (globalSection is ISerializableSolutionFileGlobalSection serializableGlobalSection)
                {
                    SolutionFileTextSerializer.SerializeGlobal(tabinatedWriter, serializableGlobalSection);
                }
                else
                {
                    throw new IOException($"Unable to serialize solution file global section type: {globalSection.GetType().FullName}");
                }
            }
            tabinatedWriter.DecreaseTabination();

            tabinatedWriter.WriteLine("EndGlobal");
        }