示例#1
0
 public static void CustomizeContentMediaSubtype(this IFixture fixture)
 {
     fixture.Customize <ContentMediaSubtype>(customization =>
                                             customization.FromFactory <int>(value =>
                                                                             ContentMediaSubtype.Parse(CreateContentMediaSubtypeString(value))
                                                                             ));
 }
示例#2
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));
        }
示例#3
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);
        }
示例#4
0
 private ContentType(ContentMediaType type, ContentMediaSubtype subtype)
 {
     _type    = type;
     _subtype = subtype;
 }
示例#5
0
 public void ParseValueCanNotBeNull()
 {
     Assert.Throws <ArgumentNullException>(() => ContentMediaSubtype.Parse(null));
 }