<PackageReference Include="System.Text.Json" Version="9.0.5" />

IEnumerableOfTConverter<TCollection, TElement>

sealed class IEnumerableOfTConverter<TCollection, TElement> : IEnumerableDefaultConverter<TCollection, TElement> where TCollection : IEnumerable<TElement>
using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace System.Text.Json.Serialization.Converters { internal sealed class IEnumerableOfTConverter<TCollection, TElement> : IEnumerableDefaultConverter<TCollection, TElement> where TCollection : IEnumerable<TElement> { private readonly bool _isDeserializable = typeof(TCollection).IsAssignableFrom(typeof(List<TElement>)); internal override bool SupportsCreateObjectDelegate => false; protected override void Add([In] [System.Runtime.CompilerServices.IsReadOnly] TElement value, ref ReadStack state) { ((List<TElement>)state.Current.ReturnValue).Add(value); } protected override void CreateCollection(ref Utf8JsonReader reader, [System.Runtime.CompilerServices.ScopedRef] ref ReadStack state, JsonSerializerOptions options) { if (!_isDeserializable) ThrowHelper.ThrowNotSupportedException_CannotPopulateCollection(Type, ref reader, ref state); state.Current.ReturnValue = new List<TElement>(); } } }