Skip to content

Commit

Permalink
Added support for setting NewLIne string for files produced by FileHe…
Browse files Browse the repository at this point in the history
…lperEngine
  • Loading branch information
Ramon Leoncio committed Nov 30, 2018
1 parent afda15e commit 8427d87
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 5 additions & 2 deletions FileHelpers/Engines/FileHelperAsyncEngine.cs
Expand Up @@ -427,7 +427,7 @@ public void Close()
var writer = mAsyncWriter;
if (writer != null) {
if (!string.IsNullOrEmpty(mFooterText)) {
if (mFooterText.EndsWith(StringHelper.NewLine))
if (mFooterText.EndsWith (NewLineForWrite))
writer.Write(mFooterText);
else
writer.WriteLine(mFooterText);
Expand Down Expand Up @@ -457,6 +457,9 @@ public IDisposable BeginWriteStream(TextWriter writer)

State = EngineState.Writing;
ResetFields();

writer.NewLine = NewLineForWrite;

mAsyncWriter = writer;
WriteHeader();
mStreamInfo = new StreamInfoProvider(mAsyncWriter);
Expand All @@ -471,7 +474,7 @@ public IDisposable BeginWriteStream(TextWriter writer)
private void WriteHeader()
{
if (!string.IsNullOrEmpty(mHeaderText)) {
if (mHeaderText.EndsWith(StringHelper.NewLine))
if (mHeaderText.EndsWith (NewLineForWrite))
mAsyncWriter.Write(mHeaderText);
else
mAsyncWriter.WriteLine(mHeaderText);
Expand Down
3 changes: 3 additions & 0 deletions FileHelpers/Engines/IFileHelperAsyncEngine.cs
Expand Up @@ -42,6 +42,9 @@ public interface IFileHelperAsyncEngine<T>
/// <summary>The read footer in the last read operation. If any.</summary>
string FooterText { get; set; }

/// <summary>Newline char or string to be used when engine writes records.</summary>
string NewLineForWrite { get; set; }

/// <summary>
/// The encoding to Read and Write the streams.
/// Default is the system's current ANSI code page.
Expand Down

0 comments on commit 8427d87

Please sign in to comment.