Пример #1
0
        public static ContentType Parse(string value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            var parts = value.Split('/');

            if (parts.Length != 2)
            {
                throw new FormatException("The content type value is not a well formed 'type/subtype'.");
            }

            var type    = ContentMediaType.Parse(parts[0]);
            var subtype = ContentMediaSubtype.Parse(parts[1]);

            return(new ContentType(type, subtype));
        }
Пример #2
0
        public static bool TryParse(string value, out ContentType parsed)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            var parts = value.Split('/');

            if (parts.Length == 2 &&
                ContentMediaType.TryParse(parts[0], out var type) &&
                ContentMediaSubtype.TryParse(parts[1], out var subtype))
            {
                parsed = new ContentType(type, subtype);
                return(true);
            }

            parsed = default;
            return(false);
        }
Пример #3
0
 public static void CustomizeContentMediaType(this IFixture fixture)
 {
     fixture.Customize <ContentMediaType>(customization =>
                                          customization.FromFactory <int>(value => ContentMediaType.Parse(CreateContentMediaTypeString(value))));
 }
Пример #4
0
 private ContentType(ContentMediaType type, ContentMediaSubtype subtype)
 {
     _type    = type;
     _subtype = subtype;
 }
Пример #5
0
 public void ParseValueCanNotBeNull()
 {
     Assert.Throws <ArgumentNullException>(() => ContentMediaType.Parse(null));
 }