public void CopyTo(T[] array, int arrayIndex) { ArgumentNullException.ThrowIfNull(array); // Allow arrayIndex == array.Length in case our own collection is empty if ((arrayIndex < 0) || (arrayIndex > array.Length)) { throw new ArgumentOutOfRangeException(nameof(arrayIndex)); } object?storeValue = _store.GetParsedAndInvalidValues(_descriptor); if (storeValue == null) { return; } List <object>?storeValues = storeValue as List <object>; if (storeValues == null) { if (storeValue is not HttpHeaders.InvalidValue) { Debug.Assert(storeValue is T); if (arrayIndex == array.Length) { throw new ArgumentException(SR.net_http_copyto_array_too_small); } array[arrayIndex] = (T)storeValue; } } else { foreach (object item in storeValues) { if (item is not HttpHeaders.InvalidValue) { Debug.Assert(item is T); if (arrayIndex == array.Length) { throw new ArgumentException(SR.net_http_copyto_array_too_small); } array[arrayIndex++] = (T)item; } } } }