<PackageReference Include="System.Text.Json" Version="4.7.0-preview3.19551.4" />

ImmutableEnumerableCreator<TElement, TCollection>

sealed class ImmutableEnumerableCreator<TElement, TCollection> : ImmutableCollectionCreator where TCollection : IEnumerable<TElement>
using System.Collections; using System.Collections.Generic; using System.Reflection; namespace System.Text.Json { internal sealed class ImmutableEnumerableCreator<TElement, TCollection> : ImmutableCollectionCreator where TCollection : IEnumerable<TElement> { private Func<IEnumerable<TElement>, TCollection> _creatorDelegate; public override void RegisterCreatorDelegateFromMethod(MethodInfo creator) { _creatorDelegate = (Func<IEnumerable<TElement>, TCollection>)creator.CreateDelegate(typeof(Func<IEnumerable<TElement>, TCollection>)); } public override bool CreateImmutableEnumerable(IList items, out IEnumerable collection) { collection = (IEnumerable)(object)_creatorDelegate(CreateGenericTElementIEnumerable(items)); return true; } public override bool CreateImmutableDictionary(IDictionary items, out IDictionary collection) { collection = null; return false; } private IEnumerable<TElement> CreateGenericTElementIEnumerable(IList sourceList) { foreach (object source in sourceList) { yield return (TElement)source; } } } }