26 lines
695 B
C#
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);
|
|
}
|
|
}
|
|
}
|