2026-06-05 13:44:39 +09:00

26 lines
695 B
C#

using System;
using System.Collections.ObjectModel;
namespace WeldingCommon.Data.Services.History.Collection
{
public class RollingCollection<T> : ObservableCollection<T>
{
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);
}
}
}