using System; using System.Collections; using System.Collections.Generic; namespace DTLib.Reactive { public class ReactiveStream : IEnumerable>, IList> { public ReactiveStream() { } List> _storage = new(); List> Storage { get { lock (_storage) return _storage; } } public int Count => Storage.Count; public TimeSignedObject this[int index] { get => Storage[index]; set => throw new NotImplementedException(); } public event Action, TimeSignedObject> ElementAddedEvent; public void Add(TimeSignedObject elem) { Storage.Add(elem); ElementAddedEvent?.Invoke(this, elem); } public void Add(T elem) => Add(new TimeSignedObject(elem)); public void Clear() => Storage.Clear(); public int IndexOf(TimeSignedObject item) => Storage.IndexOf(item); public bool Contains(TimeSignedObject item) => Storage.Contains(item); public IEnumerator> GetEnumerator() => new Enumerator(Storage); IEnumerator IEnumerable.GetEnumerator() => new Enumerator(Storage); struct Enumerator : IEnumerator> { public Enumerator(List> storage) { _storage = storage; _index = storage.Count - 1; } List> _storage; int _index; public TimeSignedObject Current => _storage[_index]; object IEnumerator.Current => Current; public void Dispose() => _storage = null; public bool MoveNext() { if (_index < 0) return false; _index--; return true; } public void Reset() => _index = _storage.Count - 1; } bool ICollection>.IsReadOnly { get; } = false; public void Insert(int index, TimeSignedObject item) => throw new NotImplementedException(); public void RemoveAt(int index) => throw new NotImplementedException(); public void CopyTo(TimeSignedObject[] array, int arrayIndex) => throw new NotImplementedException(); public bool Remove(TimeSignedObject item) => throw new NotImplementedException(); } }