< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 29
Coverable lines: 29
Total lines: 65
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
CreateReference(...)0%440%
.ctor(...)100%110%
Dispose()100%110%
DisposeInternal()0%220%
Finalize()100%110%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/Common/src/System/Net/Security/SafeCredentialReference.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.Runtime.ConstrainedExecution;
 5
 6namespace System.Net.Security
 7{
 8    //
 9    // This is a class holding a Credential handle reference, used for static handles cache
 10    //
 11    internal sealed class SafeCredentialReference : CriticalFinalizerObject, IDisposable
 12    {
 13        //
 14        // Static cache will return the target handle if found the reference in the table.
 15        //
 016        internal SafeFreeCredentials? Target { get; private set; }
 17
 18        internal static SafeCredentialReference? CreateReference(SafeFreeCredentials target)
 019        {
 020            if (target.IsInvalid || target.IsClosed)
 021            {
 022                return null;
 23            }
 24
 25            try
 026            {
 027                return new SafeCredentialReference(target);
 28            }
 029            catch (ObjectDisposedException)
 030            {
 31                // Another owner may release the last reference after the checks above.
 032                return null;
 33            }
 034        }
 35
 036        private SafeCredentialReference(SafeFreeCredentials target)
 037        {
 38            // Bumps up the refcount on Target to signify that target handle is statically cached so
 39            // its dispose should be postponed
 040            bool ignore = false;
 041            target.DangerousAddRef(ref ignore);
 042            Target = target;
 043        }
 44
 45        public void Dispose()
 046        {
 047            DisposeInternal();
 048            GC.SuppressFinalize(this);
 049        }
 50
 51        private void DisposeInternal()
 052        {
 053            SafeFreeCredentials? target = Target;
 054            target?.DangerousRelease();
 055            Target = null;
 056        }
 57
 58        ~SafeCredentialReference()
 059        {
 060            DisposeInternal();
 061        }
 62    }
 63
 64}
 65