| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | |
|
| | 5 | | public class BaseList<TValue> : IList<TValue>, IReadOnlyList<TValue> |
| | 6 | | { |
| | 7 | | private readonly List<TValue> list; |
| | 8 | |
|
| | 9 | | public event Action<TValue> OnAdded; |
| | 10 | | public event Action<TValue> OnRemoved; |
| | 11 | |
|
| 32 | 12 | | public TValue this[int index] { get => list[index]; set => list[index] = value; } |
| | 13 | |
|
| 22 | 14 | | public int Count => list.Count; |
| | 15 | |
|
| 0 | 16 | | public bool IsReadOnly => false; |
| | 17 | |
|
| 1104 | 18 | | public BaseList() : this(0) { } |
| | 19 | |
|
| 552 | 20 | | public BaseList(int capacity) |
| | 21 | | { |
| 552 | 22 | | list = new List<TValue>(capacity); |
| 552 | 23 | | } |
| | 24 | |
|
| | 25 | | public IEnumerator<TValue> GetEnumerator() |
| | 26 | | { |
| 0 | 27 | | return list.GetEnumerator(); |
| | 28 | | } |
| | 29 | |
|
| | 30 | | IEnumerator IEnumerable.GetEnumerator() |
| | 31 | | { |
| 0 | 32 | | return GetEnumerator(); |
| | 33 | | } |
| | 34 | |
|
| | 35 | | public void Add(TValue item) |
| | 36 | | { |
| 21 | 37 | | list.Add(item); |
| 21 | 38 | | OnAdded?.Invoke(item); |
| 1 | 39 | | } |
| | 40 | |
|
| | 41 | | public void Clear() |
| | 42 | | { |
| 4 | 43 | | list.Clear(); |
| 4 | 44 | | } |
| | 45 | |
|
| | 46 | | public bool Contains(TValue item) |
| | 47 | | { |
| 0 | 48 | | return list.Contains(item); |
| | 49 | | } |
| | 50 | |
|
| | 51 | | public void CopyTo(TValue[] array, int arrayIndex) |
| | 52 | | { |
| 0 | 53 | | list.CopyTo(array, arrayIndex); |
| 0 | 54 | | } |
| | 55 | |
|
| | 56 | | public bool Remove(TValue item) |
| | 57 | | { |
| 0 | 58 | | if (!list.Remove(item)) |
| 0 | 59 | | return false; |
| | 60 | |
|
| 0 | 61 | | OnRemoved?.Invoke(item); |
| 0 | 62 | | return true; |
| | 63 | | } |
| | 64 | |
|
| | 65 | | public int IndexOf(TValue item) |
| | 66 | | { |
| 0 | 67 | | return list.IndexOf(item); |
| | 68 | | } |
| | 69 | |
|
| | 70 | | public void Insert(int index, TValue item) |
| | 71 | | { |
| 0 | 72 | | list.Insert(index, item); |
| 0 | 73 | | OnAdded?.Invoke(item); |
| 0 | 74 | | } |
| | 75 | |
|
| | 76 | | public void RemoveAt(int index) |
| | 77 | | { |
| 0 | 78 | | TValue item = list[index]; |
| 0 | 79 | | list.RemoveAt(index); |
| 0 | 80 | | OnRemoved?.Invoke(item); |
| 0 | 81 | | } |
| | 82 | | } |