mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
Add struct enumerator to FateTable
This commit is contained in:
parent
23e7c164d8
commit
d1bed3ebc5
1 changed files with 27 additions and 4 deletions
|
|
@ -110,12 +110,35 @@ internal sealed partial class FateTable
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IEnumerator<IFate> GetEnumerator()
|
public IEnumerator<IFate> 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(FateTable fateTable) : IEnumerator<IFate>
|
||||||
|
{
|
||||||
|
private int index = 0;
|
||||||
|
|
||||||
|
public IFate Current { get; private set; }
|
||||||
|
|
||||||
|
object IEnumerator.Current => this.Current;
|
||||||
|
|
||||||
|
public bool MoveNext()
|
||||||
|
{
|
||||||
|
if (this.index == fateTable.Length) return false;
|
||||||
|
this.Current = fateTable[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