public FormatLookupResult GetResponseSerializer(string accept) { FormatLookupResult result = null; IEnumerable<MediaType> mediaTypes = accept.AsMediaTypes(); MediaType[] excludeTypes = mediaTypes.Where(m => m.AcceptParams.QValue <= 0).ToArray(); foreach (MediaType mediaType in mediaTypes) { if (mediaType.AcceptParams.QValue > 0) { bool found = false; foreach (IFormat format in this.Formats) { if (format.CanSerialize(mediaType) && !excludeTypes.Any(x => format.CanSerialize(x))) { result = new FormatLookupResult() { Format = format, MediaType = mediaType }; found = true; break; } } if (found) { break; } } } if (result == null && mediaTypes.Any(m => m == MediaType.Empty)) { result = ResolvedService.DefaultFormatLookupResult; } return result; }
public FormatLookupResult GetRequestDeserializer(string contentType) { FormatLookupResult result = null; MediaType mediaType = MediaType.Parse(contentType); if (mediaType != MediaType.Empty) { foreach (IFormat format in this.Formats) { if (format.CanDeserialize(mediaType)) { result = new FormatLookupResult() { Format = format, MediaType = mediaType }; break; } } } else { result = ResolvedService.DefaultFormatLookupResult; } return result; }