< Summary

Information
Class: MyNet.Collections.CollectionExtensions
Assembly: MyNet.Collections
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Collections/Extensions/CollectionExtensions.cs
Tag: 323_28699572109
Line coverage
100%
Covered lines: 8
Uncovered lines: 0
Coverable lines: 8
Total lines: 45
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
Set(...)100%11100%
AddRange(...)100%66100%

File(s)

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

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="CollectionExtensions.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Collections.Generic;
 9using System.Linq;
 10
 11#pragma warning disable IDE0130 // Namespace does not match folder structure
 12namespace MyNet.Collections;
 13#pragma warning restore IDE0130 // Namespace does not match folder structure
 14
 15public static class CollectionExtensions
 16{
 17    extension<T>(ICollection<T> collection)
 18    {
 19        /// <summary>
 20        /// Replaces the content of the collection with the specified items.
 21        /// </summary>
 22        /// <param name="items">The items to set in the collection.</param>
 23        public void Set(IEnumerable<T>? items)
 24        {
 625            collection.Clear();
 626            collection.AddRange(items);
 627        }
 28
 29        /// <summary>
 30        /// Adds a range of items to the collection.
 31        /// </summary>
 32        /// <param name="items">The items to add to the collection.</param>
 33        public void AddRange(IEnumerable<T>? items)
 34        {
 635            ArgumentNullException.ThrowIfNull(collection);
 36
 637            var materialized = items?.ToArray() ?? [];
 3038            foreach (var item in materialized)
 39            {
 940                collection.Add(item);
 41            }
 642        }
 43    }
 44}
 45