< Summary

Class:BaseDictionary_Legacy[TKey,TValue]
Assembly:ScriptableObjects
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/ScriptableObject/Variables/BaseDictionary_Legacy.cs
Covered lines:21
Uncovered lines:21
Coverable lines:42
Total lines:102
Line coverage:50% (21 of 42)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
add_OnAdded(...)0%110100%
remove_OnAdded(...)0%110100%
add_OnRemoved(...)0%2100%
remove_OnRemoved(...)0%2100%
BaseDictionary_Legacy()0%2100%
Add(...)0%330100%
Add(...)0%6200%
Remove(...)0%3.043083.33%
Remove(...)0%6200%
Get(...)0%220100%
ContainsKey(...)0%110100%
TryGetValue(...)0%110100%
GetOrDefault(...)0%6200%
GetEnumerator()0%110100%
GetValues()0%2100%
Clear()0%330100%
OnEnable()0%2100%
CleanUp()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/ScriptableObject/Variables/BaseDictionary_Legacy.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using UnityEngine;
 3
 4public class BaseDictionary_Legacy<TKey, TValue> : ScriptableObject
 5{
 6    public delegate void Added(TKey addedKey, TValue addedValue);
 7
 8    public delegate void Removed(TKey removedKey, TValue removedValue);
 9
 10    private event Added OnAddedElementValue;
 11
 12    private event Removed OnRemovedElementValue;
 13
 9014    public virtual event Added OnAdded { add => OnAddedElementValue += value; remove => OnAddedElementValue -= value; }
 15
 016    public virtual event Removed OnRemoved { add => OnRemovedElementValue += value; remove => OnRemovedElementValue -= v
 17
 018    private Dictionary<TKey, TValue> dictionary = new Dictionary<TKey, TValue>();
 19
 20    public void Add(TKey newKey, TValue newValue)
 21    {
 18322        if (dictionary.ContainsKey(newKey))
 3423            return;
 24
 14925        dictionary.Add(newKey, newValue);
 14926        OnAddedElementValue?.Invoke(newKey, newValue);
 527    }
 28
 29    public void Add(KeyValuePair<TKey, TValue>[] newValues)
 30    {
 031        int count = newValues.Length;
 032        for (int i = 0; i < count; ++i)
 33        {
 034            Add(newValues[i].Key, newValues[i].Value);
 35        }
 036    }
 37
 38    public void Remove(TKey key)
 39    {
 4040        if (!dictionary.ContainsKey(key))
 2541            return;
 42
 1543        var value = dictionary[key];
 1544        dictionary.Remove(key);
 45
 1546        OnRemovedElementValue?.Invoke(key, value);
 047    }
 48
 49    public void Remove(TKey[] keys)
 50    {
 051        int count = keys.Length;
 052        for (int i = 0; i < count; ++i)
 53        {
 054            Remove(keys[i]);
 55        }
 056    }
 57
 8758    public TValue Get(TKey key) { return dictionary.ContainsKey(key) ? dictionary[key] : default(TValue); }
 59
 7260    public bool ContainsKey(TKey key) { return dictionary.ContainsKey(key); }
 61
 6162    public bool TryGetValue(TKey key, out TValue value) { return dictionary.TryGetValue(key, out value); }
 63
 64    public TValue GetOrDefault(TKey key)
 65    {
 066        if (!dictionary.ContainsKey(key))
 067            return default;
 68
 069        return dictionary[key];
 70    }
 71
 1872    public Dictionary<TKey, TValue>.Enumerator GetEnumerator() { return dictionary.GetEnumerator(); }
 73
 074    public IEnumerable<TValue> GetValues() { return dictionary.Values; }
 75
 76    public void Clear()
 77    {
 21978        using (Dictionary<TKey, TValue>.Enumerator iterator = dictionary.GetEnumerator())
 79        {
 34580            while (iterator.MoveNext())
 81            {
 12682                OnRemovedElementValue?.Invoke(iterator.Current.Key, iterator.Current.Value);
 83            }
 21984        }
 85
 21986        dictionary.Clear();
 21987    }
 88
 89#if UNITY_EDITOR
 90    private void OnEnable()
 91    {
 092        Application.quitting -= CleanUp;
 093        Application.quitting += CleanUp;
 094    }
 95
 96    private void CleanUp()
 97    {
 098        Application.quitting -= CleanUp;
 099        Resources.UnloadAsset(this);
 0100    }
 101#endif
 102}