From 9fbe86c89591e7c94bd7f1a329ffac2b6a0c690e Mon Sep 17 00:00:00 2001 From: prozolic <42107886+prozolic@users.noreply.github.com> Date: Sun, 5 Apr 2026 20:17:28 +0900 Subject: [PATCH] Use ThrowHelper in JsonElement.GetByte/GetSByte/GetInt16/GetUInt16 Replace inline `throw new FormatException()` statements in JsonElement.GetSByte, GetByte, GetInt16, and GetUInt16 with ThrowHelper.ThrowFormatException calls, consistent with the pattern established in #61746. --- .../System/Text/Json/Document/JsonElement.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonElement.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonElement.cs index d791f189607e41..82dbd9d126bfa2 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonElement.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonElement.cs @@ -473,12 +473,12 @@ public bool TryGetSByte(out sbyte value) [CLSCompliant(false)] public sbyte GetSByte() { - if (TryGetSByte(out sbyte value)) + if (!TryGetSByte(out sbyte value)) { - return value; + ThrowHelper.ThrowFormatException(); } - throw new FormatException(); + return value; } /// @@ -523,12 +523,12 @@ public bool TryGetByte(out byte value) /// public byte GetByte() { - if (TryGetByte(out byte value)) + if (!TryGetByte(out byte value)) { - return value; + ThrowHelper.ThrowFormatException(); } - throw new FormatException(); + return value; } /// @@ -570,12 +570,12 @@ public bool TryGetInt16(out short value) /// public short GetInt16() { - if (TryGetInt16(out short value)) + if (!TryGetInt16(out short value)) { - return value; + ThrowHelper.ThrowFormatException(); } - throw new FormatException(); + return value; } /// @@ -622,12 +622,12 @@ public bool TryGetUInt16(out ushort value) [CLSCompliant(false)] public ushort GetUInt16() { - if (TryGetUInt16(out ushort value)) + if (!TryGetUInt16(out ushort value)) { - return value; + ThrowHelper.ThrowFormatException(); } - throw new FormatException(); + return value; } ///