private static IList <T> GetAdapterForEnumerable(IEnumerable <T> source, int start, int count) { return(source switch { StringSliceAdapter str_adapter => new StringSliceAdapter(str_adapter, start, count) as IList <T>, ArraySegment <T> segment => new ArraySegment <T>(segment.Array, start + segment.Offset, count), ListSliceAdapter <T> list_adapter => new ListSliceAdapter <T>(list_adapter, start, count), Memoizer <T> memo_adapter => new ListSliceAdapter <T>(memo_adapter, start, count), Slice <T> slice => GetAdapterForEnumerable(slice.adapter, start, count), string str => new StringSliceAdapter(str, start, count) as IList <T>, T[] arr when start == 0 && count == arr.Length => arr, T[] arr => new ArraySegment <T>(arr, start, count), IList <T> list when start == 0 && count == list.Count => list, IList <T> list => new ListSliceAdapter <T>(list, start, count), _ => new ListSliceAdapter <T>(new Memoizer <T>(source), start, count), });
public StringSliceAdapter(StringSliceAdapter source, int offset, int?count) : this(source.source_string, offset + source.Offset, count ?? source.end_index - (offset + source.Offset)) { }