using System; using System.Collections.ObjectModel; namespace WeldingCommon.Data.Services.History.Collection { public class RollingCollection : ObservableCollection { public int MaxCount { get; } public RollingCollection(int maxCount) { if (maxCount <= 0) throw new ArgumentOutOfRangeException(nameof(maxCount)); MaxCount = maxCount; } public void AddRolling(T item) { if (Count == MaxCount) RemoveAt(0); Add(item); } public void PrependRolling(T item) { Insert(0, item); if (Count > MaxCount) RemoveAt(Count - 1); } } }