public void Save(IEnumerable <T> items, string location) { var path = Path.GetDirectoryName(location); if (path != null && !Directory.Exists(path)) { Directory.CreateDirectory(path); } using (var scrubStream = new MemoryStream()) { _engine.Write(scrubStream, items); scrubStream.Position = 0; using (var scrubReader = new StreamReader(scrubStream)) using (var stream = File.Create(location)) using (var streamWriter = new StreamWriter(stream)) { var line = scrubReader.ReadLine(); while (line != null) { streamWriter.WriteLine(line.Englify()); line = scrubReader.ReadLine(); } } } }
public static string WriteToString <T>(this IFlatFileEngine engine, IEnumerable <T> source) where T : class, new() { using (var stream = new MemoryStream()) using (var reader = new StreamReader(stream)) { engine.Write(stream, source); stream.Position = 0; string fileContent = reader.ReadToEnd(); return(fileContent); } }