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

ICollectionOfTConverter<TCollection, TElement>

sealed class ICollectionOfTConverter<TCollection, TElement> : IEnumerableDefaultConverter<TCollection, TElement> where TCollection : ICollection<TElement>
using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text.Json.Serialization.Metadata; namespace System.Text.Json.Serialization.Converters { internal sealed class ICollectionOfTConverter<TCollection, TElement> : IEnumerableDefaultConverter<TCollection, TElement> where TCollection : ICollection<TElement> { internal override bool CanPopulate => true; protected override void Add([In] [System.Runtime.CompilerServices.IsReadOnly] TElement value, ref ReadStack state) { TCollection val = (TCollection)state.Current.ReturnValue; val.Add(value); if (base.IsValueType) state.Current.ReturnValue = val; } protected override void CreateCollection(ref Utf8JsonReader reader, [System.Runtime.CompilerServices.ScopedRef] ref ReadStack state, JsonSerializerOptions options) { base.CreateCollection(ref reader, ref state, options); if (((TCollection)state.Current.ReturnValue).IsReadOnly) { state.Current.ReturnValue = null; ThrowHelper.ThrowNotSupportedException_CannotPopulateCollection(Type, ref reader, ref state); } } internal override void ConfigureJsonTypeInfo(JsonTypeInfo jsonTypeInfo, JsonSerializerOptions options) { if (jsonTypeInfo.CreateObject == null && Type.IsAssignableFrom(typeof(List<TElement>))) jsonTypeInfo.CreateObject = (() => new List<TElement>()); } } }