41 lines
888 B
C#
41 lines
888 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
|
|
namespace PkmnLibSharp.Utilities
|
|
{
|
|
internal static class CollectionHelper
|
|
{
|
|
internal static ReadOnlyArray<T> ToReadOnly<T>(this IList<T> arr)
|
|
{
|
|
return new ReadOnlyArray<T>(arr);
|
|
}
|
|
}
|
|
|
|
public class ReadOnlyArray<T> : IReadOnlyList<T>
|
|
{
|
|
private readonly IList<T> _arr;
|
|
|
|
public ReadOnlyArray(IList<T> arr)
|
|
{
|
|
_arr = arr;
|
|
}
|
|
|
|
public IEnumerator<T> GetEnumerator()
|
|
{
|
|
return _arr.GetEnumerator();
|
|
}
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
{
|
|
return GetEnumerator();
|
|
}
|
|
|
|
public int Count => _arr.Count;
|
|
public T this[int index] => _arr[index];
|
|
|
|
public int IndexOf(T item)
|
|
{
|
|
return _arr.IndexOf(item);
|
|
}
|
|
}
|
|
} |