mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-15 05:04:15 +01:00
Add struct enumerator to BuddyList
This commit is contained in:
parent
520e3ea028
commit
8a9b47c7a4
1 changed files with 27 additions and 4 deletions
|
|
@ -130,12 +130,35 @@ internal sealed partial class BuddyList
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IEnumerator<IBuddyMember> GetEnumerator()
|
public IEnumerator<IBuddyMember> GetEnumerator()
|
||||||
{
|
{
|
||||||
for (var i = 0; i < this.Length; i++)
|
return new Enumerator(this);
|
||||||
{
|
|
||||||
yield return this[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();
|
IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();
|
||||||
|
|
||||||
|
private struct Enumerator(BuddyList buddyList) : IEnumerator<IBuddyMember>
|
||||||
|
{
|
||||||
|
private int index = 0;
|
||||||
|
|
||||||
|
public IBuddyMember Current { get; private set; }
|
||||||
|
|
||||||
|
object IEnumerator.Current => this.Current;
|
||||||
|
|
||||||
|
public bool MoveNext()
|
||||||
|
{
|
||||||
|
if (this.index == buddyList.Length) return false;
|
||||||
|
this.Current = buddyList[this.index];
|
||||||
|
this.index++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Reset()
|
||||||
|
{
|
||||||
|
this.index = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue