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)); }
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); }
public static void CustomizeContentMediaType(this IFixture fixture) { fixture.Customize <ContentMediaType>(customization => customization.FromFactory <int>(value => ContentMediaType.Parse(CreateContentMediaTypeString(value)))); }
private ContentType(ContentMediaType type, ContentMediaSubtype subtype) { _type = type; _subtype = subtype; }
public void ParseValueCanNotBeNull() { Assert.Throws <ArgumentNullException>(() => ContentMediaType.Parse(null)); }