using System; using System.Collections; using System.Collections.Generic; namespace PkmnLibSharp.Utils { public class ExternValueArray : IReadOnlyList where T : struct { private readonly Func _getLength; private readonly Func _getItem; public ExternValueArray(Func getSize, Func getItem) { _getLength = getSize; _getItem = getItem; } public IEnumerator GetEnumerator() { for (var i = 0; i < Count; i++) { yield return this[i]; } } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } public int Count => (int)_getLength(); public T this[int index] => _getItem((ulong)index); } }