< Summary

Information
Class: MyNet.Collections.StackExtensions
Assembly: MyNet.Collections
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Collections/Extensions/StackExtensions.cs
Tag: 323_28699572109
Line coverage
100%
Covered lines: 9
Uncovered lines: 0
Coverable lines: 9
Total lines: 41
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Remove(...)100%66100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Collections/Extensions/StackExtensions.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="StackExtensions.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
 10#pragma warning disable IDE0130 // Namespace does not match folder structure
 11namespace MyNet.Collections;
 12#pragma warning restore IDE0130 // Namespace does not match folder structure
 13
 14public static class StackExtensions
 15{
 16    /// <summary>
 17    /// Removes the first occurrence of the specified item from the stack. The order of the remaining items is preserved
 18    /// </summary>
 19    /// <param name="stack">The stack from which to remove the item.</param>
 20    /// <param name="item">The item to remove.</param>
 21    /// <typeparam name="T">The type of elements in the stack.</typeparam>
 22    /// <exception cref="ArgumentNullException">Thrown if the stack is null.</exception>
 23    public static void Remove<T>(this Stack<T> stack, T item)
 24    {
 1525        ArgumentNullException.ThrowIfNull(stack);
 26
 1227        var temp = new Stack<T>();
 28
 4829        while (stack.Count > 0)
 30        {
 3631            var current = stack.Pop();
 32
 3633            if (!Equals(current, item))
 2734                temp.Push(current);
 35        }
 36
 3937        while (temp.Count > 0)
 2738            stack.Push(temp.Pop());
 1239    }
 40}
 41