public static void SaveSnippetsToSingleFile( IEnumerable <Snippet> snippets, string filePath, bool onlyIfChanged = true) { if (snippets == null) { throw new ArgumentNullException(nameof(snippets)); } SaveSettings settings = CreateSaveSettings(); string content = SnippetSerializer.CreateXml(snippets, settings); if (!ShouldSave(filePath, content, Encoding.UTF8, onlyIfChanged)) { return; } using (var fileStream = new FileStream(filePath, FileMode.Create)) { Console.WriteLine($"saving file {filePath}"); SnippetSerializer.Serialize(fileStream, snippets, settings); } }
public static void SaveSnippet(Snippet snippet, string filePath, bool onlyIfChanged = true) { if (snippet == null) { throw new ArgumentNullException(nameof(snippet)); } SaveSettings settings = CreateSaveSettings(); if (!ShouldSave(snippet, filePath, settings, onlyIfChanged)) { return; } using (var fileStream = new FileStream(filePath, FileMode.Create)) { Console.WriteLine($"saving file {filePath}"); SnippetSerializer.Serialize(fileStream, snippet, settings); } }