< Summary

Information
Class: MyNet.Utilities.Suspending.SuspendScope
Assembly: MyNet.Utilities
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Utilities/Suspending/SuspendScope.cs
Tag: 323_28699572109
Line coverage
100%
Covered lines: 8
Uncovered lines: 0
Coverable lines: 8
Total lines: 50
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Dispose()100%22100%

File(s)

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

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="SuspendScope.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8
 9namespace MyNet.Utilities.Suspending;
 10
 11/// <summary>
 12/// Represents a scope for suspending or allowing operations. When disposed, it will automatically pop itself from the o
 13/// </summary>
 14internal sealed class SuspendScope : IDisposable
 15{
 16    private readonly Suspender _owner;
 17    private bool _disposed;
 18
 19    /// <summary>
 20    /// Initializes a new instance of the <see cref="SuspendScope"/> class with the specified owner and suspension state
 21    /// </summary>
 22    /// <param name="owner">The owner <see cref="Suspender"/> that manages the suspension state.</param>
 23    /// <param name="suspended">A value indicating whether the scope should start in a suspended state.</param>
 24    public SuspendScope(Suspender owner, bool suspended)
 25    {
 8126        _owner = owner;
 27        IsSuspended = suspended;
 28
 8129        _owner.Push(this);
 8130    }
 31
 32    /// <summary>
 33    /// Gets a value indicating whether operations are currently suspended within this scope. This property reflects the
 34    /// </summary>
 35    public bool IsSuspended { get; }
 36
 37    /// <summary>
 38    /// Disposes the scope, which will automatically pop it from the owning <see cref="Suspender"/> to restore the previ
 39    /// </summary>
 40    public void Dispose()
 41    {
 8742        if (_disposed)
 343            return;
 44
 8445        _owner.Pop(this);
 46
 8147        _disposed = true;
 8148    }
 49}
 50