com.alicizax.unity.cysharp..../ReadOnlyListAdaptor.cs
陈思海 4fbea560b5 init
2025-01-09 13:57:51 +08:00

26 lines
757 B
C#

using System.Collections;
using System.Collections.Generic;
namespace Cysharp.Text
{
/// <summary>
/// Most IList interface-implementing classes implement the IReadOnlyList interface.
/// This is for the rare class that does not implement the IList interface.
/// </summary>
/// <typeparam name="T"></typeparam>
internal readonly struct ReadOnlyListAdaptor<T> : IReadOnlyList<T>
{
readonly IList<T> _list;
public ReadOnlyListAdaptor(IList<T> list) => _list = list;
public T this[int index] => _list[index];
public int Count => _list.Count;
public IEnumerator<T> GetEnumerator() => _list.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
}