| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | |
|
| | 4 | | public class BaseCollection<T> : IBaseCollection<T>, IEquatable<IEnumerable<T>> |
| | 5 | | { |
| | 6 | | public event Action<IEnumerable<T>> OnSet; |
| | 7 | | public event Action<T> OnAdded; |
| | 8 | | public event Action<T> OnRemoved; |
| | 9 | |
|
| 40 | 10 | | internal readonly List<T> list = new List<T>(); |
| | 11 | |
|
| 74 | 12 | | public BaseCollection() { } |
| 9 | 13 | | public BaseCollection(IEnumerable<T> elements) { list = new List<T>(elements); } |
| | 14 | |
|
| 0 | 15 | | public IEnumerable<T> Get() => list; |
| | 16 | |
|
| 0 | 17 | | public T this[int index] { get => list[index]; set => list[index] = value; } |
| | 18 | |
|
| | 19 | | public void Set(IEnumerable<T> elements) |
| | 20 | | { |
| 15 | 21 | | list.Clear(); |
| 15 | 22 | | list.AddRange(elements); |
| | 23 | |
|
| 15 | 24 | | OnSet?.Invoke(list); |
| 4 | 25 | | } |
| | 26 | |
|
| | 27 | | public void Add(T element) |
| | 28 | | { |
| 42 | 29 | | list.Add(element); |
| 42 | 30 | | OnAdded?.Invoke(element); |
| 6 | 31 | | } |
| | 32 | |
|
| | 33 | | public bool Remove(T element) |
| | 34 | | { |
| 9 | 35 | | if (!list.Remove(element)) |
| 2 | 36 | | return false; |
| | 37 | |
|
| 7 | 38 | | OnRemoved?.Invoke(element); |
| 7 | 39 | | return true; |
| | 40 | | } |
| | 41 | |
|
| | 42 | | public void RemoveAt(int index) |
| | 43 | | { |
| 3 | 44 | | T value = list[index]; |
| 3 | 45 | | list.RemoveAt(index); |
| 3 | 46 | | OnRemoved?.Invoke(value); |
| 1 | 47 | | } |
| | 48 | |
|
| 0 | 49 | | public T ElementAt(int index) => list[index]; |
| 0 | 50 | | public int Count() => list.Count; |
| | 51 | |
|
| 30 | 52 | | public bool Contains(T element) => list.Contains(element); |
| | 53 | |
|
| 0 | 54 | | public virtual bool Equals(IEnumerable<T> other) { return EqualityComparer<IEnumerable<T>>.Default.Equals(list, othe |
| | 55 | | } |