public static ITypeSerializerRegistry Add(this ITypeSerializerRegistry typeSerializerRegistry, IEnumerable <string> mediaTypes, ITypeSerializer typeSerializer) { foreach (string mediaType in mediaTypes) { typeSerializerRegistry = typeSerializerRegistry.Add(mediaType, typeSerializer); } return(typeSerializerRegistry); }
public static ITypeSerializerRegistry Add <T>(this ITypeSerializerRegistry typeSerializerRegistry, IEnumerable <string> mediaTypes) where T : ITypeSerializer { ConstructorInfo?constructor = typeof(T).GetConstructor(new[] { typeof(ITypeSerializerRegistry) }); ITypeSerializer serializer = (ITypeSerializer?)constructor?.Invoke(new object[] { typeSerializerRegistry }) ?? Activator.CreateInstance <T>(); return(typeSerializerRegistry.Add(mediaTypes, serializer)); }