< Summary

Information
Class: System.Text.Json.Serialization.IgnoreReferenceResolver
Assembly: System.Text.Json
File(s): C:\h\w\B31A098C\w\BB5A0A33\e\runtime-utils\Runner\runtime\src\libraries\System.Text.Json\src\System\Text\Json\Serialization\IgnoreReferenceResolver.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 14
Coverable lines: 14
Total lines: 39
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
PopReferenceForCycleDetection()100%110%
ContainsReferenceForCycleDetection(...)0%220%
PushReferenceForCycleDetection(...)0%220%
AddReference(...)100%110%
GetReference(...)100%110%
ResolveReference(...)100%110%

File(s)

C:\h\w\B31A098C\w\BB5A0A33\e\runtime-utils\Runner\runtime\src\libraries\System.Text.Json\src\System\Text\Json\Serialization\IgnoreReferenceResolver.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Collections.Generic;
 5using System.Diagnostics;
 6
 7namespace System.Text.Json.Serialization
 8{
 9    internal sealed class IgnoreReferenceResolver : ReferenceResolver
 10    {
 11        // The stack of references on the branch of the current object graph, used to detect reference cycles.
 12        private Stack<ReferenceEqualsWrapper>? _stackForCycleDetection;
 13
 14        internal override void PopReferenceForCycleDetection()
 015        {
 016            Debug.Assert(_stackForCycleDetection != null);
 017            _stackForCycleDetection.Pop();
 018        }
 19
 20        internal override bool ContainsReferenceForCycleDetection(object value)
 021            => _stackForCycleDetection?.Contains(new ReferenceEqualsWrapper(value)) ?? false;
 22
 23        internal override void PushReferenceForCycleDetection(object value)
 024        {
 025            var wrappedValue = new ReferenceEqualsWrapper(value);
 26
 027            _stackForCycleDetection ??= new Stack<ReferenceEqualsWrapper>();
 28
 029            Debug.Assert(!_stackForCycleDetection.Contains(wrappedValue));
 030            _stackForCycleDetection.Push(wrappedValue);
 031        }
 32
 033        public override void AddReference(string referenceId, object value) => throw new InvalidOperationException();
 34
 035        public override string GetReference(object value, out bool alreadyExists) => throw new InvalidOperationException
 36
 037        public override object ResolveReference(string referenceId) => throw new InvalidOperationException();
 38    }
 39}