public void Save() { if (!HasChanges) { return; } foreach (var pair in _sourceLines) { if (_changedFiles.Contains(pair.Key)) { BenchmarkHelpers.WriteFileContent(pair.Key, pair.Value); } } var saveSettings = new XmlWriterSettings { Indent = true, IndentChars = "\t" }; foreach (var pair in _xmlAnnotations) { if (_changedFiles.Contains(pair.Key)) { using (var writer = XmlWriter.Create(pair.Key, saveSettings)) pair.Value.Save(writer); } } }
/// <summary>Saves modified files.</summary> public void Save() { if (!HasChanges) { return; } foreach (var pair in _sourceLines) { if (_changedFiles.Contains(pair.Key)) { BenchmarkHelpers.WriteFileContent(pair.Key, pair.Value); } } foreach (var pair in _xmlAnnotations) { if (_changedFiles.Contains(pair.Key)) { using (var writer = new StreamWriter(pair.Key)) { XmlAnnotations.Save(pair.Value, writer); } } } }
public static void TestWriteFileContent() { Environment.CurrentDirectory = TestContext.CurrentContext.TestDirectory; var expected = @"line1 line2 line3"; var lines = new[] { "line1", "line2", "line3" }; BenchmarkHelpers.WriteFileContent("deleteme.txt", lines); var allLines = File.ReadAllText("deleteme.txt"); // File.WriteAllLines appends line break at the end. File.WriteAllLines("deleteme.txt", lines); var allLinesWithLineBreak = File.ReadAllText("deleteme.txt"); File.Delete("deleteme.txt"); AreEqual(allLines, expected); AreEqual(allLinesWithLineBreak, expected + "\r\n"); }