From db19153b22098c7ffe8541fdd8a29783c66f4c4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Sun, 10 May 2026 17:45:22 +0200 Subject: [PATCH] fix: prefer AsSpan over Substring where span overloads are available --- Source/aweXpect.Json/Helpers/StringExtensions.cs | 4 ++++ Source/aweXpect.Json/Json/ExpectationJsonConverter.cs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/Source/aweXpect.Json/Helpers/StringExtensions.cs b/Source/aweXpect.Json/Helpers/StringExtensions.cs index 1dbcd68..cef809b 100644 --- a/Source/aweXpect.Json/Helpers/StringExtensions.cs +++ b/Source/aweXpect.Json/Helpers/StringExtensions.cs @@ -50,7 +50,11 @@ public static string TrimCommonWhiteSpace(this string value) sb.Append(lines[0]); foreach (string? line in lines.Skip(1)) { +#if NET8_0_OR_GREATER + sb.Append('\n').Append(line.AsSpan(commonWhiteSpace.Length)); +#else sb.Append('\n').Append(line.Substring(commonWhiteSpace.Length)); +#endif } return sb.ToString(); diff --git a/Source/aweXpect.Json/Json/ExpectationJsonConverter.cs b/Source/aweXpect.Json/Json/ExpectationJsonConverter.cs index 0c96f9a..093b7cc 100644 --- a/Source/aweXpect.Json/Json/ExpectationJsonConverter.cs +++ b/Source/aweXpect.Json/Json/ExpectationJsonConverter.cs @@ -43,7 +43,11 @@ public bool TryGetExpectation(JsonElement element, { string? value = element.GetString(); if (value?.StartsWith(Prefix) == true && +#if NET8_0_OR_GREATER + Guid.TryParse(value.AsSpan(Prefix.Length), out Guid guid) && +#else Guid.TryParse(value.Substring(Prefix.Length), out Guid guid) && +#endif _expectations.TryGetValue(guid, out Expectation? expectation) && expectation is IOptionsProvider {