Skip to content

Commit eb22697

Browse files
authored
Configuration Schema Generator: Port changes from dotnet/aspire#13529 (#1634)
1 parent 939b77a commit eb22697

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

src/Tools/src/ConfigurationSchemaGenerator/ConfigSchemaEmitter.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -721,18 +721,13 @@ private static string[] CreateExclusionPaths(List<string>? exclusionPaths)
721721

722722
private static void ReplaceNodeWithKeyCasingChange(JsonObject jsonObject, string key, JsonNode value)
723723
{
724-
// In System.Text.Json v9, the casing of the new key is not adapted. See https://github.com/dotnet/runtime/issues/108790.
725-
// So instead, remove the existing node and insert a new one with the updated key.
726-
var index = jsonObject.IndexOf(key);
727-
if (index != -1)
724+
if (!jsonObject.TryAdd(key, value, out var index))
728725
{
726+
// Starting from System.Text.Json v9, the casing of the new key is not adapted. See https://github.com/dotnet/runtime/issues/108790.
727+
// So instead, remove the existing node and insert a new one with the updated key.
729728
jsonObject.RemoveAt(index);
730729
jsonObject.Insert(index, key, value);
731730
}
732-
else
733-
{
734-
jsonObject[key] = value;
735-
}
736731
}
737732

738733
private sealed class SchemaOrderJsonNodeConverter : JsonConverter<JsonNode>

0 commit comments

Comments
 (0)