Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ArraySegment.cs
Go to the documentation of this file.
5
6namespace System;
7
9[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
11{
13 {
14 private readonly T[] _array;
15
16 private readonly int _start;
17
18 private readonly int _end;
19
20 private int _current;
21
37
38 object? IEnumerator.Current => Current;
39
41 {
42 _array = arraySegment.Array;
43 _start = arraySegment.Offset;
44 _end = arraySegment.Offset + arraySegment.Count;
45 _current = arraySegment.Offset - 1;
46 }
47
48 public bool MoveNext()
49 {
50 if (_current < _end)
51 {
52 _current++;
53 return _current < _end;
54 }
55 return false;
56 }
57
59 {
60 _current = _start - 1;
61 }
62
63 public void Dispose()
64 {
65 }
66 }
67
68 private readonly T[] _array;
69
70 private readonly int _offset;
71
72 private readonly int _count;
73
74 public static ArraySegment<T> Empty { get; } = new ArraySegment<T>(new T[0]);
75
76
77 public T[]? Array => _array;
78
79 public int Offset => _offset;
80
81 public int Count => _count;
82
83 public T this[int index]
84 {
85 get
86 {
87 if ((uint)index >= (uint)_count)
88 {
90 }
91 return _array[_offset + index];
92 }
93 set
94 {
95 if ((uint)index >= (uint)_count)
96 {
98 }
100 }
101 }
102
103 T IList<T>.this[int index]
104 {
105 get
106 {
109 {
111 }
112 return _array[_offset + index];
113 }
114 set
115 {
118 {
120 }
122 }
123 }
124
126 {
127 get
128 {
131 {
133 }
134 return _array[_offset + index];
135 }
136 }
137
139
140 public ArraySegment(T[] array)
141 {
142 if (array == null)
143 {
145 }
146 _array = array;
147 _offset = 0;
148 _count = array.Length;
149 }
150
151 public ArraySegment(T[] array, int offset, int count)
152 {
153 if (array == null || (uint)offset > (uint)array.Length || (uint)count > (uint)(array.Length - offset))
154 {
156 }
157 _array = array;
158 _offset = offset;
159 _count = count;
160 }
161
163 {
165 return new Enumerator(this);
166 }
167
168 public override int GetHashCode()
169 {
170 if (_array != null)
171 {
172 return HashCode.Combine(_offset, _count, _array.GetHashCode());
173 }
174 return 0;
175 }
176
177 public void CopyTo(T[] destination)
178 {
180 }
181
187
189 {
191 destination.ThrowInvalidOperationIfDefault();
192 if (_count > destination._count)
193 {
195 }
197 }
198
199 public override bool Equals([NotNullWhen(true)] object? obj)
200 {
202 {
203 return Equals((ArraySegment<T>)obj);
204 }
205 return false;
206 }
207
209 {
210 if (obj._array == _array && obj._offset == _offset)
211 {
212 return obj._count == _count;
213 }
214 return false;
215 }
216
218 {
220 if ((uint)index > (uint)_count)
221 {
223 }
225 }
226
228 {
230 if ((uint)index > (uint)_count || (uint)count > (uint)(_count - index))
231 {
233 }
234 return new ArraySegment<T>(_array, _offset + index, count);
235 }
236
237 public T[] ToArray()
238 {
240 if (_count == 0)
241 {
242 return Empty._array;
243 }
244 T[] array = new T[_count];
246 return array;
247 }
248
250 {
251 return a.Equals(b);
252 }
253
255 {
256 return !(a == b);
257 }
258
259 public static implicit operator ArraySegment<T>(T[] array)
260 {
261 if (array == null)
262 {
263 return default(ArraySegment<T>);
264 }
265 return new ArraySegment<T>(array);
266 }
267
268 int IList<T>.IndexOf(T item)
269 {
272 if (num < 0)
273 {
274 return -1;
275 }
276 return num - _offset;
277 }
278
279 void IList<T>.Insert(int index, T item)
280 {
282 }
283
284 void IList<T>.RemoveAt(int index)
285 {
287 }
288
293
298
300 {
303 return num >= 0;
304 }
305
307 {
309 return false;
310 }
311
316
321
323 {
324 if (_array == null)
325 {
327 }
328 }
329}
int IList. IndexOf(object value)
Definition Array.cs:1228
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
bool ICollection< KeyValuePair< TKey, TValue > >. Contains(KeyValuePair< TKey, TValue > keyValuePair)
bool ICollection< KeyValuePair< TKey, TValue > >. IsReadOnly
void Add(TKey key, TValue value)
static void ThrowNotSupportedException(ExceptionResource resource)
static void ThrowArraySegmentCtorValidationFailedExceptions(Array array, int offset, int count)
static void ThrowArgumentOutOfRange_IndexException()
static void ThrowInvalidOperationException()
static void ThrowArgumentNullException(string name)
static void ThrowArgumentException_DestinationTooShort()
static void ThrowInvalidOperationException_InvalidOperation_EnumEnded()
static void ThrowInvalidOperationException_InvalidOperation_EnumNotStarted()
new IEnumerator< T > GetEnumerator()
object? IEnumerator. Current
Enumerator(ArraySegment< T > arraySegment)
bool Equals(ArraySegment< T > obj)
ArraySegment< T > Slice(int index, int count)
static bool operator!=(ArraySegment< T > a, ArraySegment< T > b)
readonly T[] _array
void CopyTo(T[] destination)
void ThrowInvalidOperationIfDefault()
readonly int _count
readonly int _offset
override bool Equals([NotNullWhen(true)] object? obj)
void CopyTo(ArraySegment< T > destination)
void CopyTo(T[] destination, int destinationIndex)
override int GetHashCode()
static bool operator==(ArraySegment< T > a, ArraySegment< T > b)
ArraySegment< T > Slice(int index)
ArraySegment(T[] array, int offset, int count)
ArraySegment(T[] array)
Enumerator GetEnumerator()