コード例 #1
0
        void DescribesItself.Describe(Description _)
        {
            _.Title = "Content Negotiation Rules and Configuration";

            if (Formatters.Any())
            {
                _.AddList("Formatters", Formatters);
            }

            _.AddList("Rules", Rules);
            _.AddList("Conneg Querystring Rules", QuerystringParameters);

            if (Corrections.Any())
            {
                _.AddList("Mimetype Corrections", Corrections);
            }
        }
コード例 #2
0
        /// <inheritdoc />
        public MediaTypeFormatter GetFormatter(MediaTypeHeaderValue?contentType = null)
        {
            if (!Formatters.Any())
            {
                throw new InvalidOperationException("No media type formatters available.");
            }

            var formatter = contentType != null
                                ? Formatters.FirstOrDefault(x => x.SupportedMediaTypes.Any(m => m.MediaType == contentType.MediaType))
                                : DefaultFormatter ?? Formatters.FirstOrDefault();

            if (formatter == null)
            {
                throw new InvalidOperationException($"No media type formatters are available for '{contentType}' content-type.");
            }

            return(formatter);
        }