Skip to content

Commit

Permalink
Fix JsonDynamicArray enumeration in dynamic usages (#16246)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Mike Alhayek <[email protected]>
  • Loading branch information
gvkries and MikeAlhayek authored Jun 5, 2024
1 parent 77fa6e0 commit 0a96f44
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
namespace System.Text.Json.Dynamic;

[DebuggerDisplay("JsonDynamicArray[{Count}]")]
public class JsonDynamicArray : DynamicObject, IEnumerable<JsonNode?>
public class JsonDynamicArray : DynamicObject, IEnumerable<object?>, IEnumerable<JsonNode?>
{
private readonly JsonArray _jsonArray;

public readonly Dictionary<int, object?> _dictionary = [];
private readonly Dictionary<int, object?> _dictionary = [];

public JsonDynamicArray() => _jsonArray = [];

Expand Down Expand Up @@ -133,7 +132,16 @@ public void SetValue(int index, object? value)
}
}

public IEnumerator<JsonNode?> GetEnumerator() => _jsonArray.AsEnumerable().GetEnumerator();
public IEnumerator<object?> GetEnumerator()
{
for (var i = 0; i < _jsonArray.Count; i++)
{
yield return GetValue(i);
}
}

IEnumerator<JsonNode?> IEnumerable<JsonNode?>.GetEnumerator()
=> _jsonArray.AsEnumerable().GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

Expand Down

0 comments on commit 0a96f44

Please sign in to comment.