diff --git a/src/Zaabee.Extensions/Zaabee.Extensions.Bool.cs b/src/Zaabee.Extensions/Zaabee.Extensions.Bool.cs index 06f9959..f5d4e9b 100644 --- a/src/Zaabee.Extensions/Zaabee.Extensions.Bool.cs +++ b/src/Zaabee.Extensions/Zaabee.Extensions.Bool.cs @@ -24,10 +24,10 @@ public static void IfFalse(this bool b, Action action) if (!b) action(); } - public static TResult? IfTrue(this bool b, Func func) => + public static TResult? IfTrue(this bool b, Func func) => b ? func() : default; - public static TResult? IfFalse(this bool b, Func func) => + public static TResult? IfFalse(this bool b, Func func) => !b ? func() : default; public static void IfTrueElse(this bool b, Action actionTrue, Action actionElse) @@ -42,9 +42,9 @@ public static void IfFalseElse(this bool b, Action actionFalse, Action actionEls else actionElse(); } - public static TResult? IfTrueElse(this bool b, Func funcTrue, Func funcElse) => + public static TResult? IfTrueElse(this bool b, Func funcTrue, Func funcElse) => b ? funcTrue() : funcElse(); - public static TResult? IfFalseElse(this bool b, Func funcFalse, Func funcElse) => + public static TResult? IfFalseElse(this bool b, Func funcFalse, Func funcElse) => !b ? funcFalse() : funcElse(); } \ No newline at end of file diff --git a/src/Zaabee.Extensions/Zaabee.Extensions.Stream.Read.Async.cs b/src/Zaabee.Extensions/Zaabee.Extensions.Stream.Read.Async.cs index f153bf5..7525a56 100644 --- a/src/Zaabee.Extensions/Zaabee.Extensions.Stream.Read.Async.cs +++ b/src/Zaabee.Extensions/Zaabee.Extensions.Stream.Read.Async.cs @@ -35,14 +35,11 @@ public static async Task ReadToEndAsync(this Stream? stream, Cancellatio default: #if NETSTANDARD2_0 using (var memoryStream = new MemoryStream()) -#else - await using (var memoryStream = new MemoryStream()) -#endif { - -#if NETSTANDARD2_0 await stream.CopyToAsync(memoryStream); #else + await using (var memoryStream = new MemoryStream()) + { await stream.CopyToAsync(memoryStream, cancellationToken); #endif return memoryStream.ToArray(); diff --git a/src/Zaabee.Extensions/Zaabee.Extensions.Stream.Write.Async.cs b/src/Zaabee.Extensions/Zaabee.Extensions.Stream.Write.Async.cs index fd5b6b5..c3e7982 100644 --- a/src/Zaabee.Extensions/Zaabee.Extensions.Stream.Write.Async.cs +++ b/src/Zaabee.Extensions/Zaabee.Extensions.Stream.Write.Async.cs @@ -10,7 +10,11 @@ public static async Task TryWriteAsync(this Stream? stream, byte[] buffer, CancellationToken cancellationToken = default) { var canWrite = stream is not null && stream.CanWrite; +#if NETSTANDARD2_0 if (canWrite) await stream!.WriteAsync(buffer, offset, count, cancellationToken); +#else + if (canWrite) await stream!.WriteAsync(buffer.AsMemory(offset, count), cancellationToken); +#endif return canWrite; } } \ No newline at end of file diff --git a/src/Zaabee.Extensions/Zaabee.Extensions.String.cs b/src/Zaabee.Extensions/Zaabee.Extensions.String.cs index f837e58..2da651e 100644 --- a/src/Zaabee.Extensions/Zaabee.Extensions.String.cs +++ b/src/Zaabee.Extensions/Zaabee.Extensions.String.cs @@ -10,8 +10,11 @@ public static string TrimStart(this string target, string? trimString) var result = target; while (result.StartsWith(trimString)) +#if NETSTANDARD2_0 result = result.Substring(trimString!.Length); - +#else + result = result[trimString.Length..]; +#endif return result; } @@ -21,7 +24,11 @@ public static string TrimEnd(this string target, string? trimString) var result = target; while (result.EndsWith(trimString)) +#if NETSTANDARD2_0 result = result.Substring(0, result.Length - trimString!.Length); +#else + result = result[..^trimString.Length]; +#endif return result; } @@ -39,7 +46,7 @@ public static string Format(this string format, params object[] args) => string.Format(format, args); public static string GetLetterOrDigit(this string source) => - new string(source.Where(char.IsLetterOrDigit).ToArray()); + new(source.Where(char.IsLetterOrDigit).ToArray()); public static string? TryReplace(this string? str, string oldValue, string? newValue) => string.IsNullOrEmpty(str) ? str : str!.Replace(oldValue, newValue); diff --git a/src/Zaabee.Extensions/Zaabee.Extensions.csproj b/src/Zaabee.Extensions/Zaabee.Extensions.csproj index c02ede9..28fa72f 100644 --- a/src/Zaabee.Extensions/Zaabee.Extensions.csproj +++ b/src/Zaabee.Extensions/Zaabee.Extensions.csproj @@ -3,8 +3,8 @@ netstandard2.0;netcoreapp3.1;net5.0;net6.0 true - 2021.14.0 - 2021.14.0 + 2022.1.0 + 2022.1.0 Mutuduxf Mutuduxf Zaabee;Extensions