<PackageReference Include="System.Text.Json" Version="4.6.0-preview6.19259.10" />

ReadStack

struct ReadStack
using System.Collections.Generic; using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace System.Text.Json.Serialization { [DebuggerDisplay("Current: ClassType.{Current.JsonClassInfo.ClassType} {Current.JsonClassInfo.Type.Name}")] internal struct ReadStack { public ReadStackFrame Current; private List<ReadStackFrame> _previous; public int _index; public bool IsLastFrame => _index == 0; public string PropertyPath { get { StringBuilder stringBuilder = new StringBuilder(); if (_previous == null || _index == 0) stringBuilder.Append("[" + Current.JsonClassInfo.Type.FullName + "]"); else { stringBuilder.Append("[" + _previous[0].JsonClassInfo.Type.FullName + "]"); for (int i = 0; i < _index; i++) { StringBuilder stringBuilder2 = stringBuilder; ReadStackFrame frame = _previous[i]; stringBuilder2.Append(GetPropertyName(ref frame)); } } stringBuilder.Append(GetPropertyName(ref Current)); return stringBuilder.ToString(); } } public void Push() { if (_previous == null) _previous = new List<ReadStackFrame>(); if (_index == _previous.Count) _previous.Add(Current); else _previous[_index] = Current; Current.Reset(); _index++; } public void Pop() { Current = _previous[--_index]; } private string GetPropertyName([In] [System.Runtime.CompilerServices.IsReadOnly] ref ReadStackFrame frame) { if (frame.JsonPropertyInfo != null && frame.JsonClassInfo.ClassType == ClassType.Object) return "." + frame.JsonPropertyInfo.PropertyInfo.Name; return string.Empty; } } }