Created
February 14, 2023 20:45
-
-
Save jskeet/18cd6da2b2190f730e1a50d77dd5e987 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Collections.Generic; | |
public interface IWriterService | |
{ | |
Stream WriteTXT<T>(List<T> content, string delimator, string header = "", bool isHeader = false) where T : class; | |
} | |
public class WriterService : IWriterService | |
{ | |
public WriterService() | |
{} | |
public Stream WriteTXT<T>(List<T> content, string delimator, string header, bool isHeader = false) where T : class | |
{ | |
var stream = new MemoryStream(); | |
TextWriter writer = new StreamWriter(stream); | |
if (isHeader) | |
writer.Write(header); | |
foreach (var item in content) | |
{ | |
writer.Write(item); | |
writer.Write(delimator); | |
} | |
writer.Flush(); | |
stream.Position = 0; | |
return stream; | |
} | |
} | |
class PartDetailInformation {} | |
class ApiConstants | |
{ | |
public static string KroneFileDelimiter => ""; | |
public static string PartLocatorFileHeader => ""; | |
} | |
class Test | |
{ | |
static void Main() | |
{ | |
var _writerService = new WriterService(); | |
List<PartDetailInformation> partLocatorFiltered = new List<PartDetailInformation>(); | |
using var stream = _writerService.WriteTXT(partLocatorFiltered, ApiConstants.KroneFileDelimiter, ApiConstants.PartLocatorFileHeader,true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment