<PackageReference Include="System.Reactive" Version="5.0.0" />

ToList<TSource>

sealed class ToList<TSource> : Producer<IList<TSource>, _<TSource>>
using System.Collections.Generic; using System.Runtime.CompilerServices; namespace System.Reactive.Linq.ObservableImpl { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 1, 1, 1 })] internal sealed class ToList<[System.Runtime.CompilerServices.Nullable(2)] TSource> : Producer<IList<TSource>, ToList<TSource>._> { [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 1, 1 })] internal sealed class _ : Sink<TSource, IList<TSource>> { private List<TSource> _list; public _(IObserver<IList<TSource>> observer) : base(observer) { _list = new List<TSource>(); } public override void OnNext(TSource value) { _list.Add(value); } public override void OnError(Exception error) { Cleanup(); ForwardOnError(error); } public override void OnCompleted() { List<TSource> list = _list; Cleanup(); ForwardOnNext(list); ForwardOnCompleted(); } private void Cleanup() { _list = null; } } private readonly IObservable<TSource> _source; public ToList(IObservable<TSource> source) { _source = source; } [return: System.Runtime.CompilerServices.Nullable(new byte[] { 1, 0 })] protected override _ CreateSink(IObserver<IList<TSource>> observer) { return new _(observer); } protected override void Run([System.Runtime.CompilerServices.Nullable(new byte[] { 1, 0 })] _ sink) { sink.Run(_source); } } }