Skip to content

Commit

Permalink
Fixed compatibility issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshClose committed Jan 26, 2024
1 parent 53a709b commit 0c59831
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 49 deletions.
20 changes: 20 additions & 0 deletions src/CsvHelper/Compatibility/AsyncExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.IO;
using System.Threading.Tasks;

namespace CsvHelper
{
internal static class AsyncExtensions
{
#if !(NETSTANDARD2_1_OR_GREATER || NET)
public static ValueTask DisposeAsync(this TextWriter textWriter)
{
if (textWriter != null)
{
textWriter.Dispose();
}

return default;
}
#endif
}
}
5 changes: 5 additions & 0 deletions src/CsvHelper/CsvHelper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
<None Include="Icon.png" Pack="true" PackagePath="\" />
</ItemGroup>

<!-- All .NET Versions-->
<ItemGroup>
<PackageReference Include="System.Linq.Async" Version="4.0.0" />
</ItemGroup>

<!-- .NET 4.6.2 -->
<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="1.0.0" />
Expand Down
2 changes: 0 additions & 2 deletions src/CsvHelper/CsvReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,6 @@ public virtual IEnumerable<T> EnumerateRecords<T>(T record)
}
}

#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
/// <inheritdoc/>
public virtual async IAsyncEnumerable<T> GetRecordsAsync<T>([EnumeratorCancellation] CancellationToken cancellationToken = default(CancellationToken))
{
Expand Down Expand Up @@ -1211,7 +1210,6 @@ public virtual async IAsyncEnumerable<T> EnumerateRecordsAsync<T>(T record, [Enu
yield return record;
}
}
#endif

/// <summary>
/// Gets the index of the field with the given name.
Expand Down
6 changes: 0 additions & 6 deletions src/CsvHelper/CsvWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,6 @@ public virtual async Task WriteRecordsAsync<T>(IEnumerable<T> records, Cancellat
}
}

#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
/// <inheritdoc/>
public virtual async Task WriteRecordsAsync<T>(IAsyncEnumerable<T> records, CancellationToken cancellationToken = default)
{
Expand Down Expand Up @@ -493,7 +492,6 @@ public virtual async Task WriteRecordsAsync<T>(IAsyncEnumerable<T> records, Canc
throw new WriterException(context, "An unexpected error occurred. See inner exception for details.", ex);
}
}
#endif

/// <inheritdoc/>
public virtual void NextRecord()
Expand Down Expand Up @@ -725,7 +723,6 @@ protected virtual void Dispose(bool disposing)
disposed = true;
}

#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
/// <inheritdoc/>
public async ValueTask DisposeAsync()
{
Expand Down Expand Up @@ -760,9 +757,7 @@ protected virtual async ValueTask DisposeAsync(bool disposing)

disposed = true;
}
#endif

#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
private async Task<bool> WriteHeaderAsync<T>(IAsyncEnumerable<T> records)
{
if (!hasHeaderRecord || hasHeaderBeenWritten)
Expand All @@ -780,7 +775,6 @@ private async Task<bool> WriteHeaderAsync<T>(IAsyncEnumerable<T> records)

return WriteHeader(await records.FirstOrDefaultAsync());
}
#endif

private bool WriteHeader<T>(IEnumerable<T> records)
{
Expand Down
31 changes: 0 additions & 31 deletions src/CsvHelper/EnumerableExtensions.cs

This file was deleted.

2 changes: 0 additions & 2 deletions src/CsvHelper/IReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public interface IReader : IReaderRow, IDisposable
/// <returns>An <see cref="IEnumerable{T}"/> of records.</returns>
IEnumerable<T> EnumerateRecords<T>(T record);

#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
/// <summary>
/// Gets all the records in the CSV file and
/// converts each to <see cref="Type"/> T. The Read method
Expand Down Expand Up @@ -121,6 +120,5 @@ public interface IReader : IReaderRow, IDisposable
/// /// <param name="cancellationToken">The cancellation token to stop the writing.</param>
/// <returns>An <see cref="IAsyncEnumerable{T}"/> of records.</returns>
IAsyncEnumerable<T> EnumerateRecordsAsync<T>(T record, CancellationToken cancellationToken = default(CancellationToken));
#endif
}
}
7 changes: 1 addition & 6 deletions src/CsvHelper/IWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ namespace CsvHelper
/// <summary>
/// Defines methods used to write to a CSV file.
/// </summary>
public interface IWriter : IWriterRow, IDisposable
#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
, IAsyncDisposable
#endif
public interface IWriter : IWriterRow, IDisposable, IAsyncDisposable
{
/// <summary>
/// Flushes the internal buffer to the <see cref="TextWriter"/> then
Expand Down Expand Up @@ -73,14 +70,12 @@ public interface IWriter : IWriterRow, IDisposable
/// <param name="cancellationToken">The cancellation token to stop the writing.</param>
Task WriteRecordsAsync<T>(IEnumerable<T> records, CancellationToken cancellationToken = default);

#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
/// <summary>
/// Writes the list of records to the CSV file.
/// </summary>
/// <typeparam name="T">Record type.</typeparam>
/// <param name="records">The records to write.</param>
/// <param name="cancellationToken">The cancellation token to stop the writing.</param>
Task WriteRecordsAsync<T>(IAsyncEnumerable<T> records, CancellationToken cancellationToken = default);
#endif
}
}
4 changes: 2 additions & 2 deletions tests/CsvHelper.Tests/CsvHelper.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0;net48;net47;net462</TargetFrameworks>
<!--<TargetFrameworks>net8.0</TargetFrameworks>-->
<!--<TargetFrameworks>net8.0;net7.0;net6.0;net48;net47;net462</TargetFrameworks>-->
<TargetFrameworks>net8.0</TargetFrameworks>
<LangVersion>preview</LangVersion>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>CsvHelper.snk</AssemblyOriginatorKeyFile>
Expand Down

0 comments on commit 0c59831

Please sign in to comment.