Skip to content

Instantly share code, notes, and snippets.

@jskeet
Created February 14, 2023 20:45
Show Gist options
  • Save jskeet/18cd6da2b2190f730e1a50d77dd5e987 to your computer and use it in GitHub Desktop.
Save jskeet/18cd6da2b2190f730e1a50d77dd5e987 to your computer and use it in GitHub Desktop.
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