diff --git a/SharedCode.Core/Data/DataReaderExtensions.cs b/SharedCode.Core/Data/DataReaderExtensions.cs index f850917..e63d9cc 100644 --- a/SharedCode.Core/Data/DataReaderExtensions.cs +++ b/SharedCode.Core/Data/DataReaderExtensions.cs @@ -80,7 +80,11 @@ public static IList 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); @@ -89,8 +93,8 @@ public static IList 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}\""; } diff --git a/SharedCode.Core/IO/BufferedWriter.cs b/SharedCode.Core/IO/BufferedWriter.cs index c461356..6624278 100644 --- a/SharedCode.Core/IO/BufferedWriter.cs +++ b/SharedCode.Core/IO/BufferedWriter.cs @@ -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(); } @@ -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(); } } @@ -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(); } } diff --git a/SharedCode.Core/Linq/EnumerableExtensions.cs b/SharedCode.Core/Linq/EnumerableExtensions.cs index 9819bad..91218c1 100644 --- a/SharedCode.Core/Linq/EnumerableExtensions.cs +++ b/SharedCode.Core/Linq/EnumerableExtensions.cs @@ -271,8 +271,19 @@ public static int IndexOf(this IEnumerable @this, TSource valu /// /// true if the source enumerable is not null and contains items; otherwise, false. /// - public static bool IsNotNullOrEmpty(this IEnumerable @this) => - @this is not null && (@this.TryGetNonEnumeratedCount(out var count) ? count > 0 : @this.Any()); + public static bool IsNotNullOrEmpty(this IEnumerable @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 + } /// /// Determines whether the source enumerable is null or contains no items.