public static void RegisterImmutableDictionary(Type immutableCollectionType, Type elementType, JsonSerializerOptions options) { // Get a unique identifier for a delegate which will point to the appropiate CreateRange method. string delegateKey = DefaultImmutableEnumerableConverter.GetDelegateKey(immutableCollectionType, elementType, out Type underlyingType, out string constructingTypeName); // Exit if we have registered this immutable dictionary type. if (options.CreateRangeDelegatesContainsKey(delegateKey)) { return; } // Get the constructing type. Type constructingType = underlyingType.Assembly.GetType(constructingTypeName) !; // Create a delegate which will point to the CreateRange method. ImmutableCollectionCreator createRangeDelegate = options.MemberAccessorStrategy.ImmutableDictionaryCreateRange(constructingType, immutableCollectionType, elementType); // Cache the delegate options.TryAddCreateRangeDelegate(delegateKey, createRangeDelegate); }
public static void RegisterImmutableCollection(Type immutableCollectionType, Type elementType, JsonSerializerOptions options) { // Get a unique identifier for a delegate which will point to the appropiate CreateRange method. string delegateKey = GetDelegateKey(immutableCollectionType, elementType, out Type underlyingType, out string constructingTypeName); // Exit if we have registered this immutable collection type. if (options.CreateRangeDelegatesContainsKey(delegateKey)) { return; } // Get the constructing type. Type constructingType = underlyingType.Assembly.GetType(constructingTypeName); // Create a delegate which will point to the CreateRange method. object createRangeDelegate; createRangeDelegate = options.ClassMaterializerStrategy.ImmutableCollectionCreateRange(constructingType, elementType); // Cache the delegate options.TryAddCreateRangeDelegate(delegateKey, createRangeDelegate); }