using System; using System.Linq; using System.Collections.Generic; namespace UniJSON { public static partial class ArraySegmentExtensions { public static IEnumerable ToEnumerable(this ArraySegment self) { return self.Array.Skip(self.Offset).Take(self.Count); } public static void Set(this ArraySegment self, int index, T value) { if (index < 0 || index >= self.Count) { throw new ArgumentOutOfRangeException(); } self.Array[self.Offset + index] = value; } public static T Get(this ArraySegment self, int index) { if (index < 0 || index >= self.Count) { throw new ArgumentOutOfRangeException(); } return self.Array[self.Offset + index]; } public static ArraySegment Advance(this ArraySegment self, Int32 n) { return new ArraySegment(self.Array, self.Offset + n, self.Count - n); } public static ArraySegment Take(this ArraySegment self, Int32 n) { return new ArraySegment(self.Array, self.Offset, n); } public static T[] TakeReversedArray(this ArraySegment self, Int32 n) { var array = new T[n]; var x = n - 1; for (int i = 0; i < n; ++i, --x) { array[i] = self.Get(x); } return array; } } public static partial class ArraySegmentExtensions { #region JSON #endregion } }