Skip to content

Commit 5ea7bef

Browse files
committed
shorter switch
1 parent 34c5dde commit 5ea7bef

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

Src/Newtonsoft.Json/JsonPosition.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,13 @@ public JsonPosition(JsonContainerType type)
5959

6060
internal int CalculateLength()
6161
{
62-
switch (Type)
62+
return Type switch
6363
{
64-
case JsonContainerType.Object:
65-
return PropertyName!.Length + 5;
66-
case JsonContainerType.Array:
67-
case JsonContainerType.Constructor:
68-
return MathUtils.IntLength((ulong)Position) + 2;
69-
default:
70-
throw new ArgumentOutOfRangeException(nameof(Type));
71-
}
64+
JsonContainerType.Object => PropertyName!.Length + 5,
65+
JsonContainerType.Array or JsonContainerType.Constructor
66+
=> MathUtils.IntLength((ulong)Position) + 2,
67+
_ => throw new ArgumentOutOfRangeException(nameof(Type))
68+
};
7269
}
7370

7471
internal void WriteTo(StringBuilder sb, ref StringWriter? writer, ref char[]? buffer)

0 commit comments

Comments
 (0)