From 44a3eb13440a6e25bf589c1a6803e7a0f729d12a Mon Sep 17 00:00:00 2001 From: axunonb Date: Mon, 12 May 2025 14:31:41 +0200 Subject: [PATCH] Remove unnecessary `GroupedListEnumerator` --- Ical.Net/Collections/GroupedList.cs | 2 +- Ical.Net/Collections/GroupedListEnumerator.cs | 106 ------------------ 2 files changed, 1 insertion(+), 107 deletions(-) delete mode 100644 Ical.Net/Collections/GroupedListEnumerator.cs diff --git a/Ical.Net/Collections/GroupedList.cs b/Ical.Net/Collections/GroupedList.cs index 3a8067e9f..4e26757ab 100644 --- a/Ical.Net/Collections/GroupedList.cs +++ b/Ical.Net/Collections/GroupedList.cs @@ -218,7 +218,7 @@ TItem IList.this[int index] set => this[index] = value; } - public IEnumerator GetEnumerator() => new GroupedListEnumerator(_lists); + public IEnumerator GetEnumerator() => _lists.SelectMany(x => x).GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } diff --git a/Ical.Net/Collections/GroupedListEnumerator.cs b/Ical.Net/Collections/GroupedListEnumerator.cs deleted file mode 100644 index 33997caab..000000000 --- a/Ical.Net/Collections/GroupedListEnumerator.cs +++ /dev/null @@ -1,106 +0,0 @@ -// -// Copyright ical.net project maintainers and contributors. -// Licensed under the MIT license. -// - -using System; -using System.Collections; -using System.Collections.Generic; - -namespace Ical.Net.Collections; - -public class GroupedListEnumerator : - IEnumerator where TType : class -{ - private readonly IList>? _lists; - private IEnumerator>? _listsEnumerator; - private IEnumerator? _listEnumerator; - - public GroupedListEnumerator(IList> lists) => _lists = lists; - - public virtual TType Current - => _listEnumerator == null - ? throw new InvalidOperationException("List enumerator is null.") - : _listEnumerator.Current; - - public virtual void Dispose() - { - Reset(); - } - - private void DisposeListEnumerator() - { - if (_listEnumerator == null) - { - return; - } - _listEnumerator.Dispose(); - _listEnumerator = null; - } - - object IEnumerator.Current - => _listEnumerator == null - ? throw new InvalidOperationException("List enumerator is null.") - : _listEnumerator.Current; - - private bool MoveNextList() - { - if (_listsEnumerator == null) - { - _listsEnumerator = _lists?.GetEnumerator(); - } - - if (_listsEnumerator == null) - { - return false; - } - - if (!_listsEnumerator.MoveNext()) - { - return false; - } - - DisposeListEnumerator(); - - _listEnumerator = _listsEnumerator.Current.GetEnumerator(); - return true; - } - - public virtual bool MoveNext() - { - while (true) - { - if (_listEnumerator == null) - { - if (MoveNextList()) - { - continue; - } - } - else - { - if (_listEnumerator.MoveNext()) - { - return true; - } - DisposeListEnumerator(); - if (MoveNextList()) - { - continue; - } - } - return false; - } - } - - public virtual void Reset() - { - if (_listsEnumerator == null) - { - return; - } - - _listsEnumerator.Dispose(); - _listsEnumerator = null; - } -}