Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ReadOnlyList.cs
浏览该文件的文档.
1namespace Engine {
2 public struct ReadOnlyList<T> : IList<T> {
3 public struct Enumerator : IEnumerator<T> {
4 IList<T> m_list;
5
6 int m_index;
7
8 public T Current => m_list[m_index];
9
10 object IEnumerator.Current => m_list[m_index];
11
12 public Enumerator(IList<T> list) {
13 m_list = list;
14 m_index = -1;
15 }
16
17 public void Dispose() { }
18
19 public bool MoveNext() => ++m_index < m_list.Count;
20
21 public void Reset() {
22 m_index = -1;
23 }
24 }
25
26 IList<T> m_list;
27
28 static ReadOnlyList<T> m_empty = new(new T[0]);
29
30 public static ReadOnlyList<T> Empty => m_empty;
31
32 public T this[int index] {
33 get => m_list[index];
34 set => throw new NotSupportedException("List is readonly.");
35 }
36
37 public int Count => m_list.Count;
38
39 public bool IsReadOnly => true;
40
41 public ReadOnlyList(IList<T> list) => m_list = list;
42
44
45 public int IndexOf(T item) => m_list.IndexOf(item);
46
47 public void Insert(int index, T item) {
48 throw new NotSupportedException("List is readonly.");
49 }
50
51 public void RemoveAt(int index) {
52 throw new NotSupportedException("List is readonly.");
53 }
54
55 public void Add(T item) {
56 throw new NotSupportedException("List is readonly.");
57 }
58
59 public void Clear() {
60 throw new NotSupportedException("List is readonly.");
61 }
62
63 public bool Contains(T item) => m_list.Contains(item);
64
65 public void CopyTo(T[] array, int arrayIndex) {
66 m_list.CopyTo(array, arrayIndex);
67 }
68
69 public bool Remove(T item) => throw new NotSupportedException("List is readonly.");
70
71 IEnumerator<T> IEnumerable<T>.GetEnumerator() => new Enumerator(m_list);
72
73 IEnumerator IEnumerable.GetEnumerator() => new Enumerator(m_list);
74 }
75}
ReadOnlyList(IList< T > list)
void CopyTo(T[] array, int arrayIndex)
static ReadOnlyList< T > Empty
void Insert(int index, T item)
static ReadOnlyList< T > m_empty