< Summary

Information
Class: Hertzole.ScriptableValues.CollectionEnumerator[T]
Assembly: Hertzole.ScriptableValues
File(s): ./Packages/se.hertzole.scriptable-values/Runtime/Collections/Core/CollectionEnumerator.cs
Tag: 52_28197466029
Line coverage
43%
Covered lines: 16
Uncovered lines: 21
Coverable lines: 37
Total lines: 86
Line coverage: 43.2%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CollectionEnumerator()0%110100%
SetArray(...)0%110100%
Dispose()0%110100%
GetEnumerator()0%42600%
GetEnumerator()0%2100%
Add(...)0%2100%
Clear()0%2100%
Contains(...)0%2100%
CopyTo(...)0%110100%
Remove(...)0%2100%

File(s)

./Packages/se.hertzole.scriptable-values/Runtime/Collections/Core/CollectionEnumerator.cs

#LineLine coverage
 1#nullable enable
 2
 3using System;
 4using System.Collections;
 5using System.Collections.Generic;
 6using Hertzole.ScriptableValues.Helpers;
 7using UnityEngine.Pool;
 8
 9namespace Hertzole.ScriptableValues
 10{
 11    /// <summary>
 12    ///     Internal reusable collection enumerator for collections.
 13    /// </summary>
 14    /// <typeparam name="T">The type of hte items in the collection.</typeparam>
 15    internal sealed class CollectionEnumerator<T> : ICollection<T>, IDisposable
 16    {
 17        private T[]? currentArray;
 18
 619        internal static readonly ObjectPool<CollectionEnumerator<T>> enumeratorPool =
 620            new ObjectPool<CollectionEnumerator<T>>(static () => new CollectionEnumerator<T>());
 21
 525622        public int Count { get; private set; }
 23        public bool IsReadOnly
 24        {
 025            get { return true; }
 26        }
 27
 28        public void SetArray(T[] newArray, int newCount)
 131429        {
 131430            currentArray = newArray;
 131431            Count = newCount;
 131432        }
 33
 34        public void Dispose()
 131435        {
 131436            currentArray = null;
 131437            Count = 0;
 131438            enumeratorPool.Release(this);
 131439        }
 40
 41        public IEnumerator<T> GetEnumerator()
 042        {
 043            if (currentArray == null || Count == 0)
 044            {
 045                yield break;
 46            }
 47
 048            for (int i = 0; i < Count; i++)
 049            {
 050                yield return currentArray[i];
 051            }
 052        }
 53
 54        IEnumerator IEnumerable.GetEnumerator()
 055        {
 056            return GetEnumerator();
 057        }
 58
 59        public void Add(T item)
 060        {
 061            throw new NotSupportedException();
 62        }
 63
 64        public void Clear()
 065        {
 066            throw new NotSupportedException();
 67        }
 68
 69        public bool Contains(T item)
 070        {
 071            throw new NotSupportedException();
 72        }
 73
 74        public void CopyTo(T[] array, int arrayIndex)
 131475        {
 131476            Guard.IsNotNull(currentArray, nameof(currentArray));
 77
 131478            Array.Copy(currentArray, 0, array, arrayIndex, Count);
 131479        }
 80
 81        public bool Remove(T item)
 082        {
 083            throw new NotSupportedException();
 84        }
 85    }
 86}