{ if (!reader.TryReadCollectionHeader(out var length)) { value = null; return; } value = new List<T?>(length); var span = CollectionsMarshalEx.CreateSpan(value, length); var formatter = GetFormatter<T>(); for (int i = 0; i < length; i++) { formatter.Deserialize(ref this, ref span[i]); } } internal static class CollectionsMarshalEx { public static Span<T?> CreateSpan<T>( List<T?> list, int length) { list.EnsureCapacity(length); ref var view = ref Unsafe.As<List<T?>, ListView<T?>>(ref list); view._size = length; return view._items.AsSpan(0, length); } } internal sealed class ListView<T> { public T[] _items; public int _size; public int _version; }