< Summary

Information
Class: Hertzole.ScriptableValues.ScriptableList
Assembly: Hertzole.ScriptableValues
File(s): ./Packages/se.hertzole.scriptable-values/Runtime/Collections/Core/ScriptableList.cs
Tag: 52_28197466029
Line coverage
100%
Covered lines: 26
Uncovered lines: 0
Coverable lines: 26
Total lines: 154
Line coverage: 100%
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
ScriptableList()0%110100%
add_CollectionChanged(...)0%110100%
remove_CollectionChanged(...)0%110100%
IsCollectionChangedNull()0%110100%
InvokeCollectionChangedBase(...)0%110100%
ClearBaseSubscribers()0%110100%
WarnIfLeftOverSubscribers()0%110100%

File(s)

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

#LineLine coverage
 1#nullable enable
 2
 3using System.Collections.Specialized;
 4using System.ComponentModel;
 5using System.Runtime.CompilerServices;
 6using Hertzole.ScriptableValues.Helpers;
 7using UnityEngine;
 8using UnityEngine.Assertions;
 9#if SCRIPTABLE_VALUES_PROPERTIES
 10using Unity.Properties;
 11#endif
 12
 13namespace Hertzole.ScriptableValues
 14{
 15    /// <summary>
 16    ///     Base class for all <see cref="ScriptableList{T}" />.
 17    /// </summary>
 18    /// <remarks>You should probably inherit from <see cref="ScriptableList{T}" /> instead.</remarks>
 19#if UNITY_EDITOR
 20    [HelpURL(Documentation.SCRIPTABLE_LIST_URL)]
 21#endif
 22    public abstract class ScriptableList : RuntimeScriptableObject, ICanBeReadOnly, INotifyCollectionChanged
 23    {
 624        public static readonly PropertyChangingEventArgs clearOnStartChangingArgs = new PropertyChangingEventArgs(nameof
 625        public static readonly PropertyChangedEventArgs clearOnStartChangedArgs = new PropertyChangedEventArgs(nameof(Cl
 26
 627        public static readonly PropertyChangingEventArgs isReadOnlyChangingArgs = new PropertyChangingEventArgs(nameof(I
 628        public static readonly PropertyChangedEventArgs isReadOnlyChangedArgs = new PropertyChangedEventArgs(nameof(IsRe
 29
 630        public static readonly PropertyChangingEventArgs setEqualityCheckChangingArgs = new PropertyChangingEventArgs(na
 631        public static readonly PropertyChangedEventArgs setEqualityCheckChangedArgs = new PropertyChangedEventArgs(nameo
 32
 633        public static readonly PropertyChangingEventArgs countChangingArgs = new PropertyChangingEventArgs(nameof(Count)
 634        public static readonly PropertyChangedEventArgs countChangedArgs = new PropertyChangedEventArgs(nameof(Count));
 35
 636        public static readonly PropertyChangingEventArgs capacityChangingArgs = new PropertyChangingEventArgs(nameof(Cap
 637        public static readonly PropertyChangedEventArgs capacityChangedArgs = new PropertyChangedEventArgs(nameof(Capaci
 38
 39        /// <summary>
 40        ///     If <c>true</c>, an equality check will be run before setting an item through the indexer to make sure th
 41        ///     object is
 42        ///     not the same as the old one.
 43        /// </summary>
 44#if SCRIPTABLE_VALUES_PROPERTIES
 45        [CreateProperty]
 46#endif
 47        public abstract bool SetEqualityCheck { get; set; }
 48
 49        /// <summary>
 50        ///     If <c>true</c>, the <see cref="ScriptableList{T}" /> will be cleared on play mode start/game boot.
 51        /// </summary>
 52#if SCRIPTABLE_VALUES_PROPERTIES
 53        [CreateProperty]
 54#endif
 55        public abstract bool ClearOnStart { get; set; }
 56
 57        /// <summary>
 58        ///     Gets the number of elements contained in the <see cref="ScriptableList{T}" />.
 59        /// </summary>
 60        /// <returns>The number of elements contained in the <see cref="ScriptableList{T}" />.</returns>
 61#if SCRIPTABLE_VALUES_PROPERTIES
 62#if SCRIPTABLE_VALUES_PROPERTIES_SUPPORTS_READONLY
 63        [CreateProperty(ReadOnly = true)]
 64#else
 65        [CreateProperty]
 66#endif // SCRIPTABLE_VALUES_PROPERTIES_SUPPORTS_READONLY
 67#endif // SCRIPTABLE_VALUES_PROPERTIES
 68        public abstract int Count { get; protected set; }
 69
 70        /// <summary>
 71        ///     Gets the total number of elements the internal data structure can hold without resizing.
 72        /// </summary>
 73#if SCRIPTABLE_VALUES_PROPERTIES
 74        [CreateProperty]
 75#endif
 76        public abstract int Capacity { get; set; }
 77
 78        /// <summary>
 79        ///     If read only, the <see cref="ScriptableList{T}" /> cannot be changed at runtime and won't be cleared on 
 80        /// </summary>
 81#if SCRIPTABLE_VALUES_PROPERTIES
 82        [CreateProperty]
 83#endif
 84        public abstract bool IsReadOnly { get; set; }
 85
 86        protected event NotifyCollectionChangedEventHandler? OnInternalCollectionChanged;
 87
 88        event NotifyCollectionChangedEventHandler INotifyCollectionChanged.CollectionChanged
 89        {
 109890            add { OnInternalCollectionChanged += value; }
 106291            remove { OnInternalCollectionChanged -= value; }
 92        }
 93
 94        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 95        internal bool IsCollectionChangedNull()
 851496        {
 851497            return OnInternalCollectionChanged == null;
 851498        }
 99
 100        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 101        internal void InvokeCollectionChangedBase(NotifyCollectionChangedEventArgs args)
 132102        {
 132103            Assert.IsNotNull(OnInternalCollectionChanged, "Need to check for null before invoking the event using " + na
 104
 105            // The event should already be checked for null here.
 132106            OnInternalCollectionChanged!.Invoke(this, args);
 132107        }
 108
 109        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 110        internal void ClearBaseSubscribers()
 2236111        {
 2236112            OnInternalCollectionChanged = null;
 2236113        }
 114
 115        /// <inheritdoc />
 116        protected override void WarnIfLeftOverSubscribers()
 2212117        {
 2212118            base.WarnIfLeftOverSubscribers();
 2212119            EventHelper.WarnIfLeftOverSubscribers(OnInternalCollectionChanged, "INotifyCollectionChanged.CollectionChang
 2212120        }
 121
 122        /// <summary>
 123        ///     Removes all elements from the <see cref="ScriptableList{T}" />.
 124        /// </summary>
 125        /// <exception cref="System.Data.ReadOnlyException">If the object is read-only and the application is playing.</
 126        public abstract void Clear();
 127
 128        /// <summary>
 129        ///     Ensures that the list has at least the specified capacity.
 130        /// </summary>
 131        /// <param name="capacity">The minimum capacity to ensure.</param>
 132        public abstract void EnsureCapacity(int capacity);
 133
 134        /// <summary>
 135        ///     Reverses the order of the elements in the entire <see cref="ScriptableList{T}" />.
 136        /// </summary>
 137        /// <exception cref="System.Data.ReadOnlyException">If the object is read-only and the application is playing.</
 138        public abstract void Reverse();
 139
 140        /// <summary>
 141        ///     Reverses the order of the elements in the specified range.
 142        /// </summary>
 143        /// <param name="index">The starting index of the range to reverse.</param>
 144        /// <param name="count">The number of elements in the range to reverse.</param>
 145        /// <exception cref="System.Data.ReadOnlyException">If the object is read-only and the application is playing.</
 146        public abstract void Reverse(int index, int count);
 147
 148        /// <summary>
 149        ///     Sets the capacity to the actual number of elements in the <see cref="ScriptableList{T}" />, if that numb
 150        ///     than a threshold value.
 151        /// </summary>
 152        public abstract void TrimExcess();
 153    }
 154}