I'm writing an API that exports data to a Stream
:
public interface IExporter<in T>
{
Task ExportAsync(IEnumerable<T> inputs, Stream output);
}
Probably the various IExporter
implementations will use a form of TextWriter
/StreamWriter
but I don't want to enforce it on the interface.
The main problem with the usage of StreamWriter
is that by default it closes the underlying stream (I know that there's a constructor but it requires bufferSize
, I could subclass StreamWriter
but I don't like it either).
Shall I simply "own" the Stream
in my IExporter
implementation (and dispose it by disposing my StreamWriter
) or are there any better ways to handle this problem?