示例#1
0
        public IReadOnlyList <string> GetSupportedContentTypes(string contentType, Type objectType)
        {
            var jsonTypes = jsonFormatter.GetSupportedContentTypes(contentType, objectType);

            // If we're not being asked about a specific type, send them all including the json types
            if (contentType == null)
            {
                // Add our hal types to the json types
                var allTypes = halJsonMediaTypes.ToList();
                allTypes.AddRange(jsonTypes);
                return(allTypes);
            }

            // HAL types can't be subsets of those supported by the json formatter (correct?)
            // So return if supported json types are available
            if (jsonTypes != null)
            {
                return(jsonTypes);
            }

            // Finally, return supported HAL types given that requested
            List <string> supportedHalTypes = null;
            var           set = new MediaType(contentType);

            foreach (var halType in halJsonMediaTypes)
            {
                if (new MediaType(halType).IsSubsetOf(set))
                {
                    if (supportedHalTypes == null)
                    {
                        supportedHalTypes = new List <string>();
                    }
                    supportedHalTypes.Add(halType);
                }
            }

            return(supportedHalTypes);
        }