21 using System.Collections;
22 using System.Collections.Generic;
31 public sealed
class SortEnumerator<TKey> : IEnumerator<BaseData>, IDisposable
33 private readonly IEnumerable<BaseData> _data;
34 #pragma warning disable CA2213 // call csutom DisposeSafely() in Dispose()
35 private IEnumerator<BaseData> _sortedEnumerator;
36 #pragma warning restore CA2213 // call csutom DisposeSafely() in Dispose()
37 private readonly Func<BaseData, TKey> _keySelector;
44 public SortEnumerator(IEnumerable<BaseData> data, Func<BaseData, TKey> keySelector =
null)
47 _sortedEnumerator = GetSortedData().GetEnumerator();
48 _keySelector = keySelector ??= baseData => (TKey)(
object)baseData.EndTime;
66 private IEnumerable<BaseData> GetSortedData()
68 foreach (var item
in _data.OrderBy(_keySelector))
74 object IEnumerator.Current => Current;
81 get => _sortedEnumerator.Current;
94 return _sortedEnumerator.MoveNext();
102 _sortedEnumerator =
null;
110 _sortedEnumerator?.DisposeSafely();