Skip to content

Commit

Permalink
fix framework compiler flags
Browse files Browse the repository at this point in the history
  • Loading branch information
pwelter34 committed Mar 19, 2024
1 parent f543955 commit 348680d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
21 changes: 19 additions & 2 deletions src/FluentCommand.Csv/CsvCommandExtensions.cs
Expand Up @@ -25,13 +25,16 @@ public static class CsvCommandExtensions
/// </returns>
public static string QueryCsv(this IDataCommand dataCommand, CsvConfiguration csvConfiguration = default)
{
if (dataCommand is null)
throw new ArgumentNullException(nameof(dataCommand));

using var stream = _memoryStreamManager.GetStream();

QueryCsv(dataCommand, stream, csvConfiguration);

var bytes = stream.GetReadOnlySequence();

#if NETSTANDARD2_1_OR_GREATER
#if NET5_0_OR_GREATER
return Encoding.UTF8.GetString(bytes);
#else
return Encoding.UTF8.GetString(bytes.ToArray());
Expand All @@ -46,6 +49,11 @@ public static string QueryCsv(this IDataCommand dataCommand, CsvConfiguration cs
/// <param name="csvConfiguration">The configuration used for the CSV writer</param>
public static void QueryCsv(this IDataCommand dataCommand, Stream stream, CsvConfiguration csvConfiguration = default)
{
if (dataCommand is null)
throw new ArgumentNullException(nameof(dataCommand));
if (stream is null)
throw new ArgumentNullException(nameof(stream));

if (csvConfiguration == null)
csvConfiguration = new CsvConfiguration(CultureInfo.InvariantCulture) { HasHeaderRecord = true };

Expand All @@ -70,12 +78,16 @@ public static void QueryCsv(this IDataCommand dataCommand, Stream stream, CsvCon
/// </returns>
public static async Task<string> QueryCsvAsync(this IDataCommand dataCommand, CsvConfiguration csvConfiguration = default, CancellationToken cancellationToken = default)
{
if (dataCommand is null)
throw new ArgumentNullException(nameof(dataCommand));

using var stream = _memoryStreamManager.GetStream();

await QueryCsvAsync(dataCommand, stream, csvConfiguration, cancellationToken);

var bytes = stream.GetReadOnlySequence();
#if NETSTANDARD2_1_OR_GREATER

#if NET5_0_OR_GREATER
return Encoding.UTF8.GetString(bytes);
#else
return Encoding.UTF8.GetString(bytes.ToArray());
Expand All @@ -94,6 +106,11 @@ public static async Task<string> QueryCsvAsync(this IDataCommand dataCommand, Cs
/// </returns>
public static async Task QueryCsvAsync(this IDataCommand dataCommand, Stream stream, CsvConfiguration csvConfiguration = default, CancellationToken cancellationToken = default)
{
if (dataCommand is null)
throw new ArgumentNullException(nameof(dataCommand));
if (stream is null)
throw new ArgumentNullException(nameof(stream));

if (csvConfiguration == null)
csvConfiguration = new CsvConfiguration(CultureInfo.InvariantCulture) { HasHeaderRecord = true };

Expand Down
20 changes: 18 additions & 2 deletions src/FluentCommand.Json/JsonCommandExtensions.cs
Expand Up @@ -25,13 +25,16 @@ public static class JsonCommandExtensions
/// </returns>
public static string QueryJson(this IDataCommand dataCommand, JsonWriterOptions options = default)
{
if (dataCommand is null)
throw new ArgumentNullException(nameof(dataCommand));

using var stream = _memoryStreamManager.GetStream();

QueryJson(dataCommand, stream, options);

var bytes = stream.GetReadOnlySequence();

#if NETSTANDARD2_1_OR_GREATER
#if NET5_0_OR_GREATER
return Encoding.UTF8.GetString(bytes);
#else
return Encoding.UTF8.GetString(bytes.ToArray());
Expand All @@ -49,6 +52,11 @@ public static string QueryJson(this IDataCommand dataCommand, JsonWriterOptions
/// </returns>
public static void QueryJson(this IDataCommand dataCommand, Stream stream, JsonWriterOptions options = default)
{
if (dataCommand is null)
throw new ArgumentNullException(nameof(dataCommand));
if (stream is null)
throw new ArgumentNullException(nameof(stream));

var writer = new Utf8JsonWriter(stream, options);

writer.WriteStartArray();
Expand All @@ -72,13 +80,16 @@ public static void QueryJson(this IDataCommand dataCommand, Stream stream, JsonW
/// </returns>
public static async Task<string> QueryJsonAsync(this IDataCommand dataCommand, JsonWriterOptions options = default, CancellationToken cancellationToken = default)
{
if (dataCommand is null)
throw new ArgumentNullException(nameof(dataCommand));

using var stream = _memoryStreamManager.GetStream();

await QueryJsonAsync(dataCommand, stream, options, cancellationToken);

var bytes = stream.GetReadOnlySequence();

#if NETSTANDARD2_1_OR_GREATER
#if NET5_0_OR_GREATER
return Encoding.UTF8.GetString(bytes);
#else
return Encoding.UTF8.GetString(bytes.ToArray());
Expand All @@ -98,6 +109,11 @@ public static async Task<string> QueryJsonAsync(this IDataCommand dataCommand, J
/// </returns>
public static async Task QueryJsonAsync(this IDataCommand dataCommand, Stream stream, JsonWriterOptions options = default, CancellationToken cancellationToken = default)
{
if (dataCommand is null)
throw new ArgumentNullException(nameof(dataCommand));
if (stream is null)
throw new ArgumentNullException(nameof(stream));

var writer = new Utf8JsonWriter(stream, options);

writer.WriteStartArray();
Expand Down

0 comments on commit 348680d

Please sign in to comment.