main
cs 32 lines 1.15 KB
Raw
1 // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3 namespace WixToolsetTest.Converters
4 {
5 using System;
6 using System.IO;
7 using System.Text;
8 using System.Xml;
9 using System.Xml.Linq;
10
11 public abstract class BaseConverterFixture
12 {
13 protected static string UnformattedDocumentString(XDocument document, bool omitXmlDeclaration = true)
14 {
15 var sb = new StringBuilder();
16
17 using (var writer = new StringWriter(sb))
18 using (var xml = XmlWriter.Create(writer, new XmlWriterSettings { OmitXmlDeclaration = omitXmlDeclaration }))
19 {
20 document.Save(xml);
21 }
22
23 return sb.ToString().TrimStart();
24 }
25
26 protected static string[] UnformattedDocumentLines(XDocument document, bool omitXmlDeclaration = true)
27 {
28 var unformatted = UnformattedDocumentString(document, omitXmlDeclaration);
29 return unformatted.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
30 }
31 }
32 }