Skip to content

Commit c6779ba

Browse files
Add IList<T> and related APIs to JsonObject. (#103645)
* Add IList<T> and related APIs to JsonObject. * Fix missing hashcode set in OrderedDictionary.SetAt * Re-enable disabled tests * Rename JsonPropertyDictionary<T> to OrderedDictionary<TKey, TValue> --------- Co-authored-by: Stephen Toub <stoub@microsoft.com>
1 parent a33eb5c commit c6779ba

26 files changed

+1130
-728
lines changed

src/libraries/System.Text.Json/ref/System.Text.Json.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -706,11 +706,11 @@ internal JsonNode() { }
706706
public System.Text.Json.Nodes.JsonValue AsValue() { throw null; }
707707
public System.Text.Json.Nodes.JsonNode DeepClone() { throw null; }
708708
public static bool DeepEquals(System.Text.Json.Nodes.JsonNode? node1, System.Text.Json.Nodes.JsonNode? node2) { throw null; }
709-
public string GetPropertyName() { throw null; }
709+
public int GetElementIndex() { throw null; }
710710
public string GetPath() { throw null; }
711+
public string GetPropertyName() { throw null; }
712+
public System.Text.Json.JsonValueKind GetValueKind() { throw null; }
711713
public virtual T GetValue<T>() { throw null; }
712-
public JsonValueKind GetValueKind() { throw null; }
713-
public int GetElementIndex() { throw null; }
714714
public static explicit operator bool (System.Text.Json.Nodes.JsonNode value) { throw null; }
715715
public static explicit operator byte (System.Text.Json.Nodes.JsonNode value) { throw null; }
716716
public static explicit operator char (System.Text.Json.Nodes.JsonNode value) { throw null; }
@@ -801,7 +801,7 @@ internal JsonNode() { }
801801
public static System.Threading.Tasks.Task<System.Text.Json.Nodes.JsonNode?> ParseAsync(System.IO.Stream utf8Json, System.Text.Json.Nodes.JsonNodeOptions? nodeOptions = default(System.Text.Json.Nodes.JsonNodeOptions?), System.Text.Json.JsonDocumentOptions documentOptions = default(System.Text.Json.JsonDocumentOptions), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
802802
[System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Creating JsonValue instances with non-primitive types requires generating code at runtime.")]
803803
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Creating JsonValue instances with non-primitive types is not compatible with trimming. It can result in non-primitive types being serialized, which may have their members trimmed.")]
804-
public void ReplaceWith<T>(T value) { throw null; }
804+
public void ReplaceWith<T>(T value) { }
805805
public string ToJsonString(System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
806806
public override string ToString() { throw null; }
807807
public abstract void WriteTo(System.Text.Json.Utf8JsonWriter writer, System.Text.Json.JsonSerializerOptions? options = null);
@@ -811,25 +811,35 @@ public partial struct JsonNodeOptions
811811
private int _dummyPrimitive;
812812
public bool PropertyNameCaseInsensitive { readonly get { throw null; } set { } }
813813
}
814-
public sealed partial class JsonObject : System.Text.Json.Nodes.JsonNode, System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<string, System.Text.Json.Nodes.JsonNode?>>, System.Collections.Generic.IDictionary<string, System.Text.Json.Nodes.JsonNode?>, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, System.Text.Json.Nodes.JsonNode?>>, System.Collections.IEnumerable
814+
public sealed partial class JsonObject : System.Text.Json.Nodes.JsonNode, System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<string, System.Text.Json.Nodes.JsonNode?>>, System.Collections.Generic.IDictionary<string, System.Text.Json.Nodes.JsonNode?>, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, System.Text.Json.Nodes.JsonNode?>>, System.Collections.Generic.IList<System.Collections.Generic.KeyValuePair<string, System.Text.Json.Nodes.JsonNode?>>, System.Collections.IEnumerable
815815
{
816816
public JsonObject(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, System.Text.Json.Nodes.JsonNode?>> properties, System.Text.Json.Nodes.JsonNodeOptions? options = default(System.Text.Json.Nodes.JsonNodeOptions?)) { }
817817
public JsonObject(System.Text.Json.Nodes.JsonNodeOptions? options = default(System.Text.Json.Nodes.JsonNodeOptions?)) { }
818818
public int Count { get { throw null; } }
819819
bool System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<string, System.Text.Json.Nodes.JsonNode?>>.IsReadOnly { get { throw null; } }
820820
System.Collections.Generic.ICollection<string> System.Collections.Generic.IDictionary<string, System.Text.Json.Nodes.JsonNode?>.Keys { get { throw null; } }
821821
System.Collections.Generic.ICollection<System.Text.Json.Nodes.JsonNode?> System.Collections.Generic.IDictionary<string, System.Text.Json.Nodes.JsonNode?>.Values { get { throw null; } }
822+
System.Collections.Generic.KeyValuePair<string, System.Text.Json.Nodes.JsonNode?> System.Collections.Generic.IList<System.Collections.Generic.KeyValuePair<string, System.Text.Json.Nodes.JsonNode?>>.this[int index] { get { throw null; } set { } }
822823
public void Add(System.Collections.Generic.KeyValuePair<string, System.Text.Json.Nodes.JsonNode?> property) { }
823824
public void Add(string propertyName, System.Text.Json.Nodes.JsonNode? value) { }
824825
public void Clear() { }
825826
public bool ContainsKey(string propertyName) { throw null; }
826827
public static System.Text.Json.Nodes.JsonObject? Create(System.Text.Json.JsonElement element, System.Text.Json.Nodes.JsonNodeOptions? options = default(System.Text.Json.Nodes.JsonNodeOptions?)) { throw null; }
828+
public System.Collections.Generic.KeyValuePair<string, System.Text.Json.Nodes.JsonNode?> GetAt(int index) { throw null; }
827829
public System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<string, System.Text.Json.Nodes.JsonNode?>> GetEnumerator() { throw null; }
830+
public int IndexOf(string propertyName) { throw null; }
831+
public void Insert(int index, string propertyName, System.Text.Json.Nodes.JsonNode? value) { }
828832
public bool Remove(string propertyName) { throw null; }
833+
public void RemoveAt(int index) { }
834+
public void SetAt(int index, string propertyName, System.Text.Json.Nodes.JsonNode? value) { }
835+
public void SetAt(int index, System.Text.Json.Nodes.JsonNode? value) { }
829836
bool System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<string, System.Text.Json.Nodes.JsonNode?>>.Contains(System.Collections.Generic.KeyValuePair<string, System.Text.Json.Nodes.JsonNode> item) { throw null; }
830837
void System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<string, System.Text.Json.Nodes.JsonNode?>>.CopyTo(System.Collections.Generic.KeyValuePair<string, System.Text.Json.Nodes.JsonNode>[] array, int index) { }
831838
bool System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<string, System.Text.Json.Nodes.JsonNode?>>.Remove(System.Collections.Generic.KeyValuePair<string, System.Text.Json.Nodes.JsonNode> item) { throw null; }
832-
bool System.Collections.Generic.IDictionary<string, System.Text.Json.Nodes.JsonNode?>.TryGetValue(string propertyName, out System.Text.Json.Nodes.JsonNode? jsonNode) { throw null; }
839+
bool System.Collections.Generic.IDictionary<string, System.Text.Json.Nodes.JsonNode?>.TryGetValue(string propertyName, out System.Text.Json.Nodes.JsonNode jsonNode) { throw null; }
840+
int System.Collections.Generic.IList<System.Collections.Generic.KeyValuePair<string, System.Text.Json.Nodes.JsonNode?>>.IndexOf(System.Collections.Generic.KeyValuePair<string, System.Text.Json.Nodes.JsonNode> item) { throw null; }
841+
void System.Collections.Generic.IList<System.Collections.Generic.KeyValuePair<string, System.Text.Json.Nodes.JsonNode?>>.Insert(int index, System.Collections.Generic.KeyValuePair<string, System.Text.Json.Nodes.JsonNode> item) { }
842+
void System.Collections.Generic.IList<System.Collections.Generic.KeyValuePair<string, System.Text.Json.Nodes.JsonNode?>>.RemoveAt(int index) { }
833843
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; }
834844
public bool TryGetPropertyValue(string propertyName, out System.Text.Json.Nodes.JsonNode? jsonNode) { throw null; }
835845
public override void WriteTo(System.Text.Json.Utf8JsonWriter writer, System.Text.Json.JsonSerializerOptions? options = null) { }

src/libraries/System.Text.Json/src/System.Text.Json.csproj

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ The System.Text.Json library is built-in as part of the shared framework in .NET
7272
<Compile Include="System\Text\Json\JsonHelpers.cs" />
7373
<Compile Include="System\Text\Json\JsonHelpers.Date.cs" />
7474
<Compile Include="System\Text\Json\JsonHelpers.Escaping.cs" />
75-
<Compile Include="System\Text\Json\JsonPropertyDictionary.cs" />
76-
<Compile Include="System\Text\Json\JsonPropertyDictionary.KeyCollection.cs" />
77-
<Compile Include="System\Text\Json\JsonPropertyDictionary.ValueCollection.cs" />
7875
<Compile Include="System\Text\Json\JsonTokenType.cs" />
7976
<Compile Include="System\Text\Json\Nodes\JsonArray.cs" />
8077
<Compile Include="System\Text\Json\Nodes\JsonArray.IList.cs" />
@@ -85,6 +82,7 @@ The System.Text.Json library is built-in as part of the shared framework in .NET
8582
<Compile Include="System\Text\Json\Nodes\JsonNodeOptions.cs" />
8683
<Compile Include="System\Text\Json\Nodes\JsonObject.cs" />
8784
<Compile Include="System\Text\Json\Nodes\JsonObject.IDictionary.cs" />
85+
<Compile Include="System\Text\Json\Nodes\JsonObject.IList.cs" />
8886
<Compile Include="System\Text\Json\Nodes\JsonValue.CreateOverloads.cs" />
8987
<Compile Include="System\Text\Json\Nodes\JsonValue.cs" />
9088
<Compile Include="System\Text\Json\Nodes\JsonValueOfTCustomized.cs" />
@@ -354,6 +352,12 @@ The System.Text.Json library is built-in as part of the shared framework in .NET
354352
<Compile Include="$(CoreLibSharedDir)System\Reflection\NullabilityInfoContext.cs" />
355353
</ItemGroup>
356354

355+
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp' or $([MSBuild]::VersionLessThan('$(TargetFrameworkVersion)', '9.0'))">
356+
<Compile Include="System\Text\Json\OrderedDictionary.cs" />
357+
<Compile Include="System\Text\Json\OrderedDictionary.KeyCollection.cs" />
358+
<Compile Include="System\Text\Json\OrderedDictionary.ValueCollection.cs" />
359+
</ItemGroup>
360+
357361
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionGreaterThanOrEquals('$(TargetFrameworkVersion)', '7.0'))">
358362
<Compile Include="System\Text\Json\Serialization\Converters\Value\Int128Converter.cs" />
359363
<Compile Include="System\Text\Json\Serialization\Converters\Value\UInt128Converter.cs" />
@@ -376,6 +380,12 @@ The System.Text.Json library is built-in as part of the shared framework in .NET
376380
<Compile Include="System\Text\Json\Reader\JsonReaderHelper.netstandard.cs" />
377381
</ItemGroup>
378382

383+
<ItemGroup>
384+
<None Include="System\Text\Json\OrderedDictionary.cs" />
385+
<None Include="System\Text\Json\OrderedDictionary.KeyCollection.cs" />
386+
<None Include="System\Text\Json\OrderedDictionary.ValueCollection.cs" />
387+
</ItemGroup>
388+
379389
<!-- Application tfms (.NETCoreApp, .NETFramework) need to use the same or higher version of .NETStandard's dependencies. -->
380390
<ItemGroup>
381391
<ProjectReference Include="$(LibrariesProjectRoot)System.Text.Encodings.Web\src\System.Text.Encodings.Web.csproj" />

src/libraries/System.Text.Json/src/System/Text/Json/JsonPropertyDictionary.ValueCollection.cs

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
 (0)