From 257d387984784f2c8074abf8f02ca7cea2523765 Mon Sep 17 00:00:00 2001 From: karashiiro <49822414+karashiiro@users.noreply.github.com> Date: Wed, 22 Apr 2020 12:09:08 -0700 Subject: [PATCH] Implement IReadOnlyCollection, see #92 --- Dalamud/Game/ClientState/PartyList.cs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/Dalamud/Game/ClientState/PartyList.cs b/Dalamud/Game/ClientState/PartyList.cs index edb6206e7..07c1d08ae 100644 --- a/Dalamud/Game/ClientState/PartyList.cs +++ b/Dalamud/Game/ClientState/PartyList.cs @@ -10,9 +10,8 @@ using System.Text; using System.Threading.Tasks; namespace Dalamud.Game.ClientState - { - public class PartyList : ICollection, IDisposable + public class PartyList : IReadOnlyCollection, ICollection, IDisposable { private ClientStateAddressResolver Address { get; } private Dalamud dalamud; @@ -73,7 +72,7 @@ namespace Dalamud.Game.ClientState } } - private class PartyListEnumerator : IEnumerator + private class PartyListEnumerator : IEnumerator { private readonly PartyList party; private int currentIndex; @@ -83,8 +82,6 @@ namespace Dalamud.Game.ClientState party = list; } - public object Current => party[currentIndex]; - public bool MoveNext() { currentIndex++; @@ -95,15 +92,27 @@ namespace Dalamud.Game.ClientState { currentIndex = 0; } + + public PartyMember Current => this.party[this.currentIndex]; + + object IEnumerator.Current => Current; + + // Required by IEnumerator even though we have nothing we want to dispose here. + public void Dispose() {} } - public IEnumerator GetEnumerator() - { + public IEnumerator GetEnumerator() { return new PartyListEnumerator(this); } + IEnumerator IEnumerable.GetEnumerator() { + return GetEnumerator(); + } + public int Length => !this.isReady ? 0 : Marshal.ReadByte(partyListBegin + 0xF0); + int IReadOnlyCollection.Count => Length; + public int Count => Length; public object SyncRoot => this;