Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use switch statement instead of multiple ifs
  • Loading branch information
andrewjsaid committed Jun 27, 2024
commit 50c06bef90a6eb8bfdfc51840e304e0114d18df3
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;
Expand Down Expand Up @@ -181,20 +180,22 @@ internal static JsonValue CreateFromTypeInfo<T>(T value, JsonTypeInfo<T> jsonTyp

internal static JsonValue? CreateFromElement(ref readonly JsonElement element, JsonNodeOptions? options = null)
{
JsonValueKind kind = element.ValueKind;

if (kind is JsonValueKind.Null)
switch (element.ValueKind)
{
return null;
}
case JsonValueKind.Null:
return null;

// Force usage of JsonArray and JsonObject instead of supporting those in an JsonValue.
if (kind is JsonValueKind.Object or JsonValueKind.Array)
{
ThrowHelper.ThrowInvalidOperationException_NodeElementCannotBeObjectOrArray();
}
case JsonValueKind.Object:
case JsonValueKind.Array:
// Force usage of JsonArray and JsonObject instead of supporting those in an JsonValue.
ThrowHelper.ThrowInvalidOperationException_NodeElementCannotBeObjectOrArray();

// The above method will throw, but the compiler doesn't know that.
return default;

return new JsonValueOfElement(element, options);
default:
return new JsonValueOfElement(element, options);
}
}
}
}