コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }