当前位置: 首页>>代码示例>>C#>>正文


C# MediaType.IsSubsetOf方法代码示例

本文整理汇总了C#中MediaType.IsSubsetOf方法的典型用法代码示例。如果您正苦于以下问题:C# MediaType.IsSubsetOf方法的具体用法?C# MediaType.IsSubsetOf怎么用?C# MediaType.IsSubsetOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MediaType的用法示例。


在下文中一共展示了MediaType.IsSubsetOf方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CanWriteResult

        /// <inheritdoc />
        public virtual bool CanWriteResult(OutputFormatterCanWriteContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (SupportedMediaTypes.Count == 0)
            {
                var message = Resources.FormatFormatter_NoMediaTypes(
                    GetType().FullName,
                    nameof(SupportedMediaTypes));

                throw new InvalidOperationException(message);
            }

            if (!CanWriteType(context.ObjectType))
            {
                return false;
            }

            if (!context.ContentType.HasValue)
            {
                // If the desired content type is set to null, then the current formatter can write anything
                // it wants.
                context.ContentType = new StringSegment(SupportedMediaTypes[0]);
                return true;
            }
            else
            {
                // Confirm this formatter supports a more specific media type than requested e.g. OK if "text/*"
                // requested and formatter supports "text/plain". contentType is typically what we got in an Accept
                // header.
                var parsedContentType = new MediaType(context.ContentType);
                for (var i = 0; i < SupportedMediaTypes.Count; i++)
                {
                    var supportedMediaType = new MediaType(SupportedMediaTypes[i]);
                    if (supportedMediaType.IsSubsetOf(parsedContentType))
                    {
                        context.ContentType = new StringSegment(SupportedMediaTypes[i]);
                        return true;
                    }
                }
            }

            return false;
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:48,代码来源:OutputFormatter.cs

示例2: GetSupportedContentTypes

        /// <inheritdoc />
        public virtual IReadOnlyList<string> GetSupportedContentTypes(
            string contentType,
            Type objectType)
        {
            if (SupportedMediaTypes.Count == 0)
            {
                var message = Resources.FormatFormatter_NoMediaTypes(
                    GetType().FullName,
                    nameof(SupportedMediaTypes));

                throw new InvalidOperationException(message);
            }

            if (!CanWriteType(objectType))
            {
                return null;
            }

            if (contentType == null)
            {
                // If contentType is null, then any type we support is valid.
                return SupportedMediaTypes;
            }
            else
            {
                List<string> mediaTypes = null;

                var parsedContentType = new MediaType(contentType);

                // Confirm this formatter supports a more specific media type than requested e.g. OK if "text/*"
                // requested and formatter supports "text/plain". Treat contentType like it came from an Accept header.
                foreach (var mediaType in SupportedMediaTypes)
                {
                    var parsedMediaType = new MediaType(mediaType);
                    if (parsedMediaType.IsSubsetOf(parsedContentType))
                    {
                        if (mediaTypes == null)
                        {
                            mediaTypes = new List<string>();
                        }

                        mediaTypes.Add(mediaType);
                    }
                }

                return mediaTypes;
            }
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:49,代码来源:OutputFormatter.cs

示例3: IsSubsetOf

        public void IsSubsetOf(string set, string subset, bool expectedResult)
        {
            // Arrange
            var setMediaType = new MediaType(set);
            var subSetMediaType = new MediaType(subset);

            // Act
            var result = subSetMediaType.IsSubsetOf(setMediaType);

            // Assert
            Assert.Equal(expectedResult, result);
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:12,代码来源:MediaTypeTest.cs

示例4: IsSuperSetOfAnySupportedMediaType

        private bool IsSuperSetOfAnySupportedMediaType(string contentType, MediaTypeCollection supportedMediaTypes)
        {
            var parsedContentType = new MediaType(contentType);
            for (var i = 0; i < supportedMediaTypes.Count; i++)
            {
                var supportedMediaType = new MediaType(supportedMediaTypes[i]);
                if (supportedMediaType.IsSubsetOf(parsedContentType))
                {
                    return true;
                }
            }

            return false;
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:14,代码来源:FormatFilter.cs

示例5: IsSubsetOfAnyContentType

 private bool IsSubsetOfAnyContentType(string requestMediaType)
 {
     var parsedRequestMediaType = new MediaType(requestMediaType);
     for (var i = 0; i < ContentTypes.Count; i++)
     {
         var contentTypeMediaType = new MediaType(ContentTypes[i]);
         if (parsedRequestMediaType.IsSubsetOf(contentTypeMediaType))
         {
             return true;
         }
     }
     return false;
 }
开发者ID:cemalshukriev,项目名称:Mvc,代码行数:13,代码来源:ConsumesAttribute.cs

示例6: SelectFormatterUsingSortedAcceptHeadersAndContentTypes

 /// <summary>
 /// Selects the <see cref="IOutputFormatter"/> to write the response based on the content type values
 /// present in <paramref name="sortedAcceptableContentTypes"/> and <paramref name="possibleOutputContentTypes"/>.
 /// </summary>
 /// <param name="formatterContext">The <see cref="OutputFormatterWriteContext"/>.</param>
 /// <param name="formatters">
 /// The list of <see cref="IOutputFormatter"/> instances to consider.
 /// </param>
 /// <param name="sortedAcceptableContentTypes">
 /// The ordered content types from the <c>Accept</c> header, sorted by descending q-value.
 /// </param>
 /// <param name="possibleOutputContentTypes">
 /// The ordered content types from <see cref="ObjectResult.ContentTypes"/> in descending priority order.
 /// </param>
 /// <returns>
 /// The selected <see cref="IOutputFormatter"/> or <c>null</c> if no formatter can write the response.
 /// </returns>
 protected virtual IOutputFormatter SelectFormatterUsingSortedAcceptHeadersAndContentTypes(
     OutputFormatterWriteContext formatterContext,
     IList<IOutputFormatter> formatters,
     IList<MediaTypeSegmentWithQuality> sortedAcceptableContentTypes,
     MediaTypeCollection possibleOutputContentTypes)
 {
     for (var i = 0; i < sortedAcceptableContentTypes.Count; i++) 
     {
         var acceptableContentType = new MediaType(sortedAcceptableContentTypes[i].MediaType);
         for (var j = 0; j < possibleOutputContentTypes.Count; j++) 
         {
             var candidateContentType = new MediaType(possibleOutputContentTypes[j]);
             if (candidateContentType.IsSubsetOf(acceptableContentType)) 
             {
                 for (var k = 0; k < formatters.Count; k++) 
                 {
                     var formatter = formatters[k];
                     formatterContext.ContentType = new StringSegment(possibleOutputContentTypes[j]);
                     if (formatter.CanWriteResult(formatterContext)) 
                     {
                         return formatter;
                     }
                 }
             }
         }
     }
     
     return null;
 }
开发者ID:xuchrist,项目名称:Mvc,代码行数:46,代码来源:ObjectResultExecutor.cs

示例7: InAcceptableMediaTypes

        private static bool InAcceptableMediaTypes(StringSegment mediaType, MediaTypeCollection acceptableMediaTypes)
        {
            if (acceptableMediaTypes.Count == 0)
            {
                return true;
            }

            var parsedMediaType = new MediaType(mediaType);
            for (int i = 0; i < acceptableMediaTypes.Count; i++)
            {
                var acceptableMediaType = new MediaType(acceptableMediaTypes[i]);
                if (acceptableMediaType.IsSubsetOf(parsedMediaType))
                {
                    return true;
                }
            }

            return false;
        }
开发者ID:cemalshukriev,项目名称:Mvc,代码行数:19,代码来源:ObjectResultExecutor.cs


注:本文中的MediaType.IsSubsetOf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。