Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions SharedCode.Core/Data/DataReaderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ public static IList<string> ToDelimited(this IDataReader @this, string separator
if (@this.GetFieldType(index) == typeof(string))
{
// If double quotes are used in value, ensure each are replaced but 2.
if (value?.Contains('"', StringComparison.Ordinal) == true)
#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
if (value?.IndexOf('"', StringComparison.Ordinal) >= 0)
#else
if (value?.IndexOf('"') >= 0)
#endif
{
#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
value = value.Replace("\"", "\"\"", StringComparison.Ordinal);
Expand All @@ -89,8 +93,8 @@ public static IList<string> ToDelimited(this IDataReader @this, string separator
#endif
}

// If separtor are is in value, ensure it is put in double quotes.
if (value?.Contains(separator, StringComparison.Ordinal) == true)
// If separator is in value, ensure it is put in double quotes.
if (value?.IndexOf(separator, StringComparison.Ordinal) >= 0)
{
value = $"\"{value}\"";
}
Expand Down
18 changes: 18 additions & 0 deletions SharedCode.Core/IO/BufferedWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ public async Task FullFlushAsync(CancellationToken token)

if (this.StringBuilder.Length > 0)
{
#if NET8_0_OR_GREATER
await this.writer.WriteAsync(this.StringBuilder, token).ConfigureAwait(false);
#else
token.ThrowIfCancellationRequested();
// Older targets do not expose a cancellable TextWriter string overload.
await this.writer.WriteAsync(this.StringBuilder.ToString()).ConfigureAwait(false);
#endif
_ = this.StringBuilder.Clear();
}

Expand Down Expand Up @@ -102,7 +108,13 @@ public async Task StrongFlushAsync(CancellationToken token)

if (this.StringBuilder.Length > 0)
{
#if NET8_0_OR_GREATER
await this.writer.WriteAsync(this.StringBuilder, token).ConfigureAwait(true);
#else
token.ThrowIfCancellationRequested();
// Older targets do not expose a cancellable TextWriter string overload.
await this.writer.WriteAsync(this.StringBuilder.ToString()).ConfigureAwait(true);
#endif
_ = this.StringBuilder.Clear();
}
}
Expand All @@ -128,7 +140,13 @@ public async Task WeakFlushAsync(CancellationToken token = default)
{
if (this.StringBuilder.Length > BufferLength)
{
#if NET8_0_OR_GREATER
await this.writer.WriteAsync(this.StringBuilder, token).ConfigureAwait(true);
#else
token.ThrowIfCancellationRequested();
// Older targets do not expose a cancellable TextWriter string overload.
await this.writer.WriteAsync(this.StringBuilder.ToString()).ConfigureAwait(true);
#endif
_ = this.StringBuilder.Clear();
}
}
Expand Down
15 changes: 13 additions & 2 deletions SharedCode.Core/Linq/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,19 @@ public static int IndexOf<TSource>(this IEnumerable<TSource> @this, TSource valu
/// <returns>
/// <c>true</c> if the source enumerable is not null and contains items; otherwise, <c>false</c>.
/// </returns>
public static bool IsNotNullOrEmpty<T>(this IEnumerable<T> @this) =>
@this is not null && (@this.TryGetNonEnumeratedCount(out var count) ? count > 0 : @this.Any());
public static bool IsNotNullOrEmpty<T>(this IEnumerable<T> @this)
{
if (@this is null)
{
return false;
}

#if NET6_0_OR_GREATER
return @this.TryGetNonEnumeratedCount(out var count) ? count > 0 : @this.Any();
#else
return @this.Any();
#endif
}

/// <summary>
/// Determines whether the source enumerable is null or contains no items.
Expand Down
Loading