private void CreateNodes() { if (_list == null) { List <JsonNode?> list; if (_jsonElement == null) { list = new List <JsonNode?>(); } else { JsonElement jElement = _jsonElement.Value; Debug.Assert(jElement.ValueKind == JsonValueKind.Array); list = new List <JsonNode?>(jElement.GetArrayLength()); foreach (JsonElement element in jElement.EnumerateArray()) { JsonNode?node = JsonNodeConverter.Create(element, Options); node?.AssignParent(this); list.Add(node); } // Clear since no longer needed. _jsonElement = null; } _list = list; } }
internal void SetItem(string propertyName, JsonNode?value) { InitializeIfRequired(); Debug.Assert(_dictionary != null); JsonNode?existing = _dictionary.SetValue(propertyName, value, () => value?.AssignParent(this)); DetachParent(existing); }
internal void SetItem(int index, JsonNode?value) { value?.AssignParent(this); DetachParent(List[index]); List[index] = value; }