Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove writable JSON DOM #34099

Merged
merged 2 commits into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
267 changes: 0 additions & 267 deletions src/libraries/System.Text.Json/ref/System.Text.Json.cs

Large diffs are not rendered by default.

17 changes: 0 additions & 17 deletions src/libraries/System.Text.Json/src/System.Text.Json.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -207,23 +207,6 @@
<Compile Include="System\Text\Json\Writer\Utf8JsonWriter.WriteValues.String.cs" />
<Compile Include="System\Text\Json\Writer\Utf8JsonWriter.WriteValues.UnsignedNumber.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="System\Text\Json\Node\DuplicatePropertyNameHandlingStrategy.cs" />
<Compile Include="System\Text\Json\Node\JsonArray.cs" />
<Compile Include="System\Text\Json\Node\JsonArrayEnumerator.cs" />
<Compile Include="System\Text\Json\Node\JsonBoolean.cs" />
<Compile Include="System\Text\Json\Node\JsonNode.cs" />
<Compile Include="System\Text\Json\Node\JsonNode.RecursionStackFrame.cs" />
<Compile Include="System\Text\Json\Node\JsonNode.Traversal.cs" />
<Compile Include="System\Text\Json\Node\JsonNode.TraversalHelpers.cs" />
<Compile Include="System\Text\Json\Node\JsonNodeOptions.cs" />
<Compile Include="System\Text\Json\Node\JsonNull.cs" />
<Compile Include="System\Text\Json\Node\JsonNumber.cs" />
<Compile Include="System\Text\Json\Node\JsonObject.cs" />
<Compile Include="System\Text\Json\Node\JsonObjectEnumerator.cs" />
<Compile Include="System\Text\Json\Node\JsonObjectProperty.cs" />
<Compile Include="System\Text\Json\Node\JsonString.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsNetStandard)' == 'true' or '$(TargetsNetFx)' == 'true'">
<Compile Include="System\Collections\Generic\StackExtensions.netstandard.cs" />
<!-- Common or Common-branched source files -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,10 @@ internal ArrayEnumerator(JsonElement target)
{
_target = target;
_curIdx = -1;
Debug.Assert(target._parent != null);

if (target._parent is JsonDocument document)
{
Debug.Assert(target.TokenType == JsonTokenType.StartArray);
Debug.Assert(target.TokenType == JsonTokenType.StartArray);

_endIdxOrVersion = document.GetEndIndex(_target._idx, includeEndElement: false);
}
else
{
var jsonArray = (JsonArray)target._parent;
_endIdxOrVersion = jsonArray._version;
}
_endIdxOrVersion = target._parent.GetEndIndex(_target._idx, includeEndElement: false);
}

/// <inheritdoc />
Expand All @@ -49,18 +40,7 @@ public JsonElement Current
return default;
}

if (_target._parent is JsonArray jsonArray)
{
if (_curIdx >= jsonArray.Count)
{
return default;
}

return jsonArray[_curIdx].AsJsonElement();
}

var document = (JsonDocument)_target._parent;
return new JsonElement(document, _curIdx);
return new JsonElement(_target._parent, _curIdx);
}
}

Expand Down Expand Up @@ -102,22 +82,6 @@ public void Reset()
/// <inheritdoc />
public bool MoveNext()
{
if (_target._parent is JsonArray jsonArray)
{
if (jsonArray._version != _endIdxOrVersion)
{
throw new InvalidOperationException(SR.ArrayModifiedDuringIteration);
}

if (_curIdx >= jsonArray.Count)
{
return false;
}

_curIdx++;
return _curIdx < jsonArray.Count;
}

if (_curIdx >= _endIdxOrVersion)
{
return false;
Expand All @@ -129,9 +93,7 @@ public bool MoveNext()
}
else
{
Debug.Assert(_target._parent != null);
var document = (JsonDocument)_target._parent;
_curIdx = document.GetEndIndex(_curIdx, includeEndElement: true);
_curIdx = _target._parent.GetEndIndex(_curIdx, includeEndElement: true);
}

return _curIdx < _endIdxOrVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,49 +19,27 @@ public struct ObjectEnumerator : IEnumerable<JsonProperty>, IEnumerator<JsonProp
private readonly JsonElement _target;
private int _curIdx;
private readonly int _endIdxOrVersion;
private JsonObjectProperty? _current;

internal ObjectEnumerator(JsonElement target)
{
_target = target;
_curIdx = -1;
_current = null;
Debug.Assert(target._parent != null);

if (target._parent is JsonDocument document)
{
Debug.Assert(target.TokenType == JsonTokenType.StartObject);
_endIdxOrVersion = document.GetEndIndex(_target._idx, includeEndElement: false);
}
else
{
var jsonObject = (JsonObject)target._parent;
_endIdxOrVersion = jsonObject._version;
}
Debug.Assert(target.TokenType == JsonTokenType.StartObject);
_endIdxOrVersion = target._parent.GetEndIndex(_target._idx, includeEndElement: false);
}

/// <inheritdoc />
public JsonProperty Current
{
get
{
if (_target._parent is JsonNode)
{
if (_current == null)
{
return default;
}

return new JsonProperty(_current.Value.AsJsonElement(), _current.Name);
}

if (_curIdx < 0)
{
return default;
}

var document = (JsonDocument)_target._parent;
return new JsonProperty(new JsonElement(document, _curIdx));
return new JsonProperty(new JsonElement(_target._parent, _curIdx));
}
}

Expand Down Expand Up @@ -95,14 +73,12 @@ public ObjectEnumerator GetEnumerator()
public void Dispose()
{
_curIdx = _endIdxOrVersion;
_current = null;
}

/// <inheritdoc />
public void Reset()
{
_curIdx = -1;
_current = null;
}

/// <inheritdoc />
Expand All @@ -111,28 +87,6 @@ public void Reset()
/// <inheritdoc />
public bool MoveNext()
{
if (_target._parent is JsonObject jsonObject)
{
if (jsonObject._version != _endIdxOrVersion)
{
throw new InvalidOperationException(SR.ArrayModifiedDuringIteration);
}

if (_current == null)
{
_current = jsonObject._first;
return true;
}

if (_current.Next != null)
{
_current = _current.Next;
return true;
}

return false;
}

if (_curIdx >= _endIdxOrVersion)
{
return false;
Expand All @@ -144,9 +98,7 @@ public bool MoveNext()
}
else
{
Debug.Assert(_target._parent != null);
var document = (JsonDocument)_target._parent;
_curIdx = document.GetEndIndex(_curIdx, includeEndElement: true);
_curIdx = _target._parent.GetEndIndex(_curIdx, includeEndElement: true);
}

// _curIdx is now pointing at a property name, move one more to get the value
Expand Down
Loading