Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/libraries/System.Text.Json/src/System.Text.Json.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ The System.Text.Json library is built-in as part of the shared framework in .NET
<Compile Include="$(CommonPath)Polyfills\StopwatchPolyfills.cs" Link="Common\Polyfills\StopwatchPolyfills.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp' or $([MSBuild]::VersionLessThan('$(TargetFrameworkVersion)', '9.0'))">
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
<!-- Dependencies for System.Collections.Generic.OrderedDictionary -->
<Compile Include="$(CoreLibSharedDir)System\Collections\HashHelpers.cs" Link="Common\System\Collections\HashHelpers.cs" />
<Compile Include="$(CoreLibSharedDir)System\Collections\Generic\DebugViewDictionaryItem.cs" Link="Common\System\Collections\Generic\DebugViewDictionaryItem.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,7 @@ public bool TryAdd(string propertyName, JsonNode? value, out int index)
{
ThrowHelper.ThrowArgumentNullException(nameof(propertyName));
}
#if NET9_0
bool success = Dictionary.TryAdd(propertyName, value);
index = success ? Dictionary.Count - 1 : Dictionary.IndexOf(propertyName);
#else
bool success = Dictionary.TryAdd(propertyName, value, out index);
#endif
if (success)
{
value?.AssignParent(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,7 @@ public bool TryGetPropertyValue(string propertyName, out JsonNode? jsonNode, out
{
ArgumentNullException.ThrowIfNull(propertyName);

#if NET9_0
index = Dictionary.IndexOf(propertyName);
if (index < 0)
{
jsonNode = null;
return false;
}

jsonNode = Dictionary.GetAt(index).Value;
return true;
#else
return Dictionary.TryGetValue(propertyName, out jsonNode, out index);
#endif
}

/// <inheritdoc/>
Expand Down Expand Up @@ -287,17 +275,8 @@ internal void SetItem(string propertyName, JsonNode? value)

OrderedDictionary<string, JsonNode?> dict = Dictionary;

if (
#if NET9_0
!dict.TryAdd(propertyName, value)
#else
!dict.TryAdd(propertyName, value, out int index)
#endif
)
if (!dict.TryAdd(propertyName, value, out int index))
{
#if NET9_0
int index = dict.IndexOf(propertyName);
#endif
Debug.Assert(index >= 0);
JsonNode? replacedValue = dict.GetAt(index).Value;

Expand Down
Loading