public static HttpContent Serialize <T>(this ITypeSerializerRegistry typeSerializerRegistry, T value, string mediaType) { if (!typeSerializerRegistry.TryGet(mediaType, out ITypeSerializer? typeSerializer)) { throw new UnknownMediaTypeException(mediaType); } return(typeSerializer.Serialize(value, mediaType)); }
public static ValueTask <T> DeserializeAsync <T>(this ITypeSerializerRegistry typeSerializerRegistry, HttpContent content) { string mediaType = content.Headers.ContentType.MediaType; if (!typeSerializerRegistry.TryGet(mediaType, out ITypeSerializer? typeSerializer)) { throw new UnknownMediaTypeException(mediaType, content); } return(typeSerializer.DeserializeAsync <T>(content)); }