Merge pull request #93 from karashiiro/minor-tweaks

Implement IReadOnlyCollection on PartyList, see #92
This commit is contained in:
goaaats 2020-04-22 21:15:02 +02:00 committed by GitHub
commit b1202d4be7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,9 +10,8 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Dalamud.Game.ClientState namespace Dalamud.Game.ClientState
{ {
public class PartyList : ICollection, IDisposable public class PartyList : IReadOnlyCollection<PartyMember>, ICollection, IDisposable
{ {
private ClientStateAddressResolver Address { get; } private ClientStateAddressResolver Address { get; }
private Dalamud dalamud; private Dalamud dalamud;
@ -73,7 +72,7 @@ namespace Dalamud.Game.ClientState
} }
} }
private class PartyListEnumerator : IEnumerator private class PartyListEnumerator : IEnumerator<PartyMember>
{ {
private readonly PartyList party; private readonly PartyList party;
private int currentIndex; private int currentIndex;
@ -83,8 +82,6 @@ namespace Dalamud.Game.ClientState
party = list; party = list;
} }
public object Current => party[currentIndex];
public bool MoveNext() public bool MoveNext()
{ {
currentIndex++; currentIndex++;
@ -95,15 +92,27 @@ namespace Dalamud.Game.ClientState
{ {
currentIndex = 0; currentIndex = 0;
} }
public PartyMember Current => this.party[this.currentIndex];
object IEnumerator.Current => Current;
// Required by IEnumerator<T> even though we have nothing we want to dispose here.
public void Dispose() {}
} }
public IEnumerator GetEnumerator() public IEnumerator<PartyMember> GetEnumerator() {
{
return new PartyListEnumerator(this); return new PartyListEnumerator(this);
} }
IEnumerator IEnumerable.GetEnumerator() {
return GetEnumerator();
}
public int Length => !this.isReady ? 0 : Marshal.ReadByte(partyListBegin + 0xF0); public int Length => !this.isReady ? 0 : Marshal.ReadByte(partyListBegin + 0xF0);
int IReadOnlyCollection<PartyMember>.Count => Length;
public int Count => Length; public int Count => Length;
public object SyncRoot => this; public object SyncRoot => this;