Exemple #1
0
        public static T ParseFrom <T>(string mediaTypeDescriptor, MediaTypeDescriptor.Builder <T> builder) where T : MediaTypeDescriptor
        {
            var descriptorParts = mediaTypeDescriptor.Split(MediaTypeDescriptor.ParameterSeparator);

            if (descriptorParts.Length > 1)
            {
                ParseAttributes(builder, new ArraySegment <string>(descriptorParts, 1, descriptorParts.Length - 1));
            }

            var mimeParts = descriptorParts[0].Split(MediaTypeDescriptor.MimeSubtypeSeparator);

            if (mimeParts.Length == MimeTypeAndSubtypeSize)
            {
                builder.WithMimeType(mimeParts[0].Trim())
                .WithMimeSubType(mimeParts[1].Trim());
            }

            return(builder.Build());
        }
Exemple #2
0
        public static T ParseFrom <T>(string mediaTypeDescriptor, MediaTypeDescriptor.Builder <T> builder) where T : MediaTypeDescriptor
        {
            var descriptorParts = mediaTypeDescriptor.Split(MediaTypeDescriptor.PARAMETER_SEPARATOR);

            if (descriptorParts.Length > 1)
            {
                ParseAttributes(builder, new ArraySegment <string>(descriptorParts, 1, descriptorParts.Length - 1));
            }

            var mimeParts = descriptorParts[0].Split(MediaTypeDescriptor.MIME_SUBTYPE_SEPARATOR);

            if (mimeParts.Length == MIME_TYPE_AND_SUBTYPE_SIZE)
            {
                builder.WithMimeType(mimeParts[0].Trim())
                .WithMimeSubType(mimeParts[1].Trim());
            }

            return(builder.Build());
        }