public ITomlConverter CreateConverter(Type typeToConvert, ITomlSerializerContext context) { var typeToCreate = context.GetDefaultImplementation(typeToConvert) ?? typeToConvert; var constructor = GetConstructorForDeserialization(typeToCreate); var parameterConverters = constructor.GetParameters().Select(p => GetCachedParameterInfo(p, context)); return((ITomlConverter)Activator.CreateInstance( typeof(ObjectConverter <>).MakeGenericType(typeToConvert), constructor, parameterConverters.ToImmutableList()) !); }
public ITomlConverter CreateConverter(Type typeToConvert, ITomlSerializerContext context) { var itemType = IsIEnumerable(typeToConvert) ? typeToConvert.GetGenericArguments()[0] : typeToConvert.GetInterfaces().Single(IsIEnumerable).GetGenericArguments()[0]; var typeToCreate = context.GetDefaultImplementation(typeToConvert) ?? typeToConvert; var factory = CollectionCreatorFactories.FirstOrDefault(f => f.CanCreate(typeToCreate, itemType)) ?? throw new TomlException($"No creator found for collection {typeToCreate}"); return((ITomlConverter)Activator.CreateInstance( typeof(CollectionConverter <,>).MakeGenericType(typeToConvert, itemType), factory.CreateCollectionCreator(typeToCreate, itemType), context) !); }