< Summary

Information
Class: MyNet.Utilities.Suspending.Suspender
Assembly: MyNet.Utilities
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Utilities/Suspending/Suspender.cs
Tag: 323_28699572109
Line coverage
100%
Covered lines: 9
Uncovered lines: 0
Coverable lines: 9
Total lines: 47
Line coverage: 100%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
get_IsSuspended()100%22100%
Suspend()100%11100%
Resume()100%11100%
Push(...)100%11100%
Pop(...)75%44100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Utilities/Suspending/Suspender.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="Suspender.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Collections.Generic;
 9
 10namespace MyNet.Utilities.Suspending;
 11
 12/// <summary>
 13/// Provides an implementation of the <see cref="ISuspender"/> interface, allowing operations to be suspended and resume
 14/// </summary>
 15public class Suspender : ISuspender
 16{
 249017    private readonly Stack<SuspendScope> _scopes = new();
 18
 19    /// <inheritdoc/>
 667220    public bool IsSuspended => _scopes.TryPeek(out var scope) && scope.IsSuspended;
 21
 22    /// <inheritdoc/>
 6923    public IDisposable Suspend() => new SuspendScope(this, true);
 24
 25    /// <inheritdoc/>
 1226    public IDisposable Resume() => new SuspendScope(this, false);
 27
 28    /// <summary>
 29    /// Pushes a new suspend scope onto the stack. This method is called by the <see cref="SuspendScope"/> constructor t
 30    /// </summary>
 31    /// <param name="scope">The suspend scope to push onto the stack.</param>
 8132    internal void Push(SuspendScope scope) => _scopes.Push(scope);
 33
 34    /// <summary>
 35    /// Pops the specified suspend scope from the stack. This method is called by the <see cref="SuspendScope"/> Dispose
 36    /// </summary>
 37    /// <param name="scope">The suspend scope to pop from the stack.</param>
 38    /// <exception cref="InvalidOperationException">Thrown if the scopes are not disposed in the correct order.</excepti
 39    internal void Pop(SuspendScope scope)
 40    {
 8441        if (!_scopes.TryPeek(out var current) || !ReferenceEquals(current, scope))
 342            throw new InvalidOperationException("Suspend scopes must be disposed in reverse order.");
 43
 8144        _scopes.Pop();
 8145    }
 46}
 47