예제 #1
0
        public string From <T>(T data, ContentMediaType contentMediaType)
        {
            var baseType = contentMediaType.ToBaseType();

            if (_mappersByContentType.ContainsKey(baseType))
            {
                return(_mappersByContentType[baseType].From(data) !);
            }
            throw new MediaTypeNotSupportedException(contentMediaType.ToString());
        }
예제 #2
0
    public Response ResponseFrom(Request request, MediaTypeMapper mapper)
    {
        var acceptedMediaTypes        = request.HeaderValueOr(RequestHeader.Accept, DefaultMediaType.ToString());
        var responseMediaTypeSelector = new ResponseMediaTypeSelector(acceptedMediaTypes);
        var responseContentMediaType  = responseMediaTypeSelector.SelectType(mapper.MappedMediaTypes);
        var bodyContent = mapper.From(_entity, responseContentMediaType);
        var body        = Body.From(bodyContent);

        _headers.Add(ResponseHeader.Of(ResponseHeader.ContentType, responseContentMediaType.ToString()));

        return(Response.Of(_version, _status, _headers, body));
    }