Ejemplo n.º 1
0
        public void Save(string fileName)
        {
            // StringWriter.Encoding always returns UTF16. We need it to return UTF8, so the
            // XmlDocument will write the UTF8 header.

            if (!this.Settings.MaintainOriginalItemOrder)
            {
                ItemGroups.Each(group =>
                {
                    XmlElement[] elements = null;
                    elements = @group.Items.Select(x => x.Element).OrderBy(x => x.GetAttribute("Include")).ToArray();

                    group.Element.RemoveAll();

                    elements.Each(x => group.Element.AppendChild(x));

                });
            }


            var sw = new ProjectWriter(bom);
            sw.NewLine = newLine;
            doc.Save(sw);

            string content = sw.ToString();
            if (endsWithEmptyLine && !content.EndsWith(newLine))
                content += newLine;

            var shouldSave = !this.Settings.OnlySaveIfChanged ||
                             (File.Exists(fileName) && !File.ReadAllText(fileName).Equals(content));

            if (shouldSave)
                new FileSystem().WriteStringToFile(fileName, content);
        }
Ejemplo n.º 2
0
        public void Save(string fileName)
        {
            // StringWriter.Encoding always returns UTF16. We need it to return UTF8, so the
            // XmlDocument will write the UTF8 header.
            ProjectWriter sw = new ProjectWriter(bom);

            sw.NewLine = newLine;
            doc.Save(sw);

            string content = sw.ToString();

            if (endsWithEmptyLine && !content.EndsWith(newLine))
            {
                content += newLine;
            }

            TextFile.WriteFile(fileName, content, bom, true);
        }
Ejemplo n.º 3
0
        public string SaveToString()
        {
            // StringWriter.Encoding always returns UTF16. We need it to return UTF8, so the
            // XmlDocument will write the UTF8 header.
            ProjectWriter sw = new ProjectWriter(bom);

            sw.NewLine = newLine;
            doc.Save(sw);

            string content = sw.ToString();

            if (endsWithEmptyLine && !content.EndsWith(newLine))
            {
                content += newLine;
            }

            return(content);
        }
Ejemplo n.º 4
0
        string SaveToString(WriteContext ctx)
        {
            // StringWriter.Encoding always returns UTF16. We need it to return UTF8, so the
            // XmlDocument will write the UTF8 header.
            ProjectWriter sw = new ProjectWriter(format.ByteOrderMark);

            sw.NewLine = format.NewLine;
            var xw = XmlWriter.Create(sw, new XmlWriterSettings {
                OmitXmlDeclaration = !hadXmlDeclaration,
                NewLineChars       = format.NewLine,
                NewLineHandling    = NewLineHandling.Replace
            });

            MSBuildWhitespace.Write(initialWhitespace, xw);

            Save(xw);

            xw.Dispose();

            return(sw.ToString());
        }
Ejemplo n.º 5
0
		public string SaveToString ()
		{
			// StringWriter.Encoding always returns UTF16. We need it to return UTF8, so the
			// XmlDocument will write the UTF8 header.
			ProjectWriter sw = new ProjectWriter (bom);
			sw.NewLine = newLine;
			doc.Save (sw);

			string content = sw.ToString ();
			if (endsWithEmptyLine && !content.EndsWith (newLine))
				content += newLine;

			return content;
		}
Ejemplo n.º 6
0
		public void Save (string fileName)
		{
			// StringWriter.Encoding always returns UTF16. We need it to return UTF8, so the
			// XmlDocument will write the UTF8 header.
			ProjectWriter sw = new ProjectWriter (bom);
			sw.NewLine = newLine;
			doc.Save (sw);

			string content = sw.ToString ();
			if (endsWithEmptyLine && !content.EndsWith (newLine))
				content += newLine;

			TextFile.WriteFile (fileName, content, bom, true);
		}
Ejemplo n.º 7
0
		string SaveToString (WriteContext ctx)
		{
			// StringWriter.Encoding always returns UTF16. We need it to return UTF8, so the
			// XmlDocument will write the UTF8 header.
			ProjectWriter sw = new ProjectWriter (format.ByteOrderMark);
			sw.NewLine = format.NewLine;
			var xw = XmlWriter.Create (sw, new XmlWriterSettings {
				OmitXmlDeclaration = !hadXmlDeclaration,
				NewLineChars = format.NewLine,
				NewLineHandling = NewLineHandling.Replace
			});

			MSBuildWhitespace.Write (initialWhitespace, xw);

			Save (xw);

			xw.Dispose ();

			return sw.ToString ();
		}
Ejemplo n.º 8
0
        public void Save(string fileName)
        {
            // StringWriter.Encoding always returns UTF16. We need it to return UTF8, so the
            // XmlDocument will write the UTF8 header.

            if (!this.Settings.MaintainOriginalItemOrder)
            {
                ItemGroups.Each(group =>
                {
                    XmlElement[] elements = null;
                    elements = @group.Items.Select(x => x.Element).OrderBy(x => x.GetAttribute("Include")).ToArray();

                    group.Element.RemoveAll();

                    elements.Each(x => group.Element.AppendChild(x));

                });
            }

            var sw = new ProjectWriter(bom);
            sw.NewLine = newLine;
            doc.Save(sw);

            string content = sw.ToString();
            if (endsWithEmptyLine && !content.EndsWith(newLine))
                content += newLine;

            var shouldSave = !this.Settings.OnlySaveIfChanged ||
                             (File.Exists(fileName) && !File.ReadAllText(fileName).Equals(content));

            if (shouldSave)
                new FileSystem().WriteStringToFile(fileName, content);
        }
Ejemplo n.º 9
0
        public void Save(string fileName)
        {
            // StringWriter.Encoding always returns UTF16. We need it to return UTF8, so the
            // XmlDocument will write the UTF8 header.

            ItemGroups.Each(group => {
                var elements = group.Items.Select(x => x.Element).OrderBy(x => x.GetAttribute("Include")).ToArray();
                group.Element.RemoveAll();

                elements.Each(x => group.Element.AppendChild(x));

            });

            var sw = new ProjectWriter(bom);
            sw.NewLine = newLine;
            doc.Save(sw);

            string content = sw.ToString();
            if (endsWithEmptyLine && !content.EndsWith(newLine))
                content += newLine;

            new FileSystem().WriteStringToFile(fileName, content);
        }
Ejemplo n.º 10
0
        public void Save(string fileName)
        {
            // StringWriter.Encoding always returns UTF16. We need it to return UTF8, so the
            // XmlDocument will write the UTF8 header.

            ItemGroups.Each(group => {
                var items = group.Items.ToArray();
                group.Element.RemoveAll();

                var orderedItems = items.OrderBy(x => x.Name).ThenBy(x => x.Include);
                orderedItems
                     .Each(item => group.AddNewItem(item.Name, item.Include));
            });

            var sw = new ProjectWriter(bom);
            sw.NewLine = newLine;
            doc.Save(sw);

            string content = sw.ToString();
            if (endsWithEmptyLine && !content.EndsWith(newLine))
                content += newLine;

            new FileSystem().WriteStringToFile(fileName, content);
        }