public static string GetMemberValue(this ContentDispositionType type) { return(type switch { ContentDispositionType.Inline => "inline", ContentDispositionType.Attachment => "attachment", _ => throw new ArgumentOutOfRangeException(nameof(type), type, null) });
private void Parse(string contentDisposition) { if (contentDisposition != null) { string[] splitted = contentDisposition.Split(new char[] { ';' }); for (int i = 0; i < splitted.Length - 1; i++) { int firstQuote1 = splitted[i].IndexOf("\""); if (firstQuote1 > -1) { int secondQuote1 = splitted[i].IndexOf("\"", firstQuote1 + 1); int firstQuote2 = splitted[i + 1].IndexOf("\""); if (firstQuote2 > -1) { int secondQuote2 = splitted[i + 1].IndexOf("\"", firstQuote2 + 1); if (firstQuote1 > 0 && secondQuote1 == -1 && firstQuote2 > 0 && secondQuote2 == -1) { splitted[i] = splitted[i] + ";" + splitted[i + 1]; splitted[i + 1] = ""; } } } } if (splitted.Length > 0) { this.type = EnumUtil.ParseContentDispositionType(splitted[0]); } for (int i = 1; i < splitted.Length; i++) { splitted[i] = splitted[i].Trim(); if (splitted[i].Length > 0) { int equalIndex = splitted[i].IndexOf("="); if (equalIndex > -1) { string parameterName = splitted[i].Substring(0, equalIndex); string parameterValue = splitted[i].Substring(equalIndex + 1); parameterName = parameterName.Trim(); parameterValue = parameterValue.Trim(new char[] { '"', ' ' }); Parameter parameter = new Parameter(parameterName, parameterValue); parameters.Add(parameter); } } } } }
internal static string ParseContentDispositionType(ContentDispositionType dispositionType) { if (dispositionType == ContentDispositionType.Inline) { return("inline"); } else { return("attachment"); } }
public void contentdisposition___ctor_basic_returns_type(string type, ContentDispositionType expected) { var header = new ContentDispositionHeader($"{type}"); header.Should().NotBeNull(); header.Type.Should().Be(expected); header.FileName.Should().BeEmpty(); header.FileNameStar.Should().BeEmpty(); header.Name.Should().BeEmpty(); header.Size.Should().BeNull(); header.CreationDate.Should().BeNull(); header.ModificationDate.Should().BeNull(); header.ReadDate.Should().BeNull(); header.Value.Should().Be($"{type}"); }
public void Set(ContentDispositionType type, string?filename = null) { if (type == ContentDispositionType.Attachment && filename == null) { throw new ArgumentException("You have to supply a filename", nameof(filename)); } if (type == ContentDispositionType.Inline && filename != null) { throw new ArgumentException("You supplied a filename to Inline. That is not permitted", nameof(filename)); } _type = type; _filename = filename; }
public Upload WithContentDisposition(ContentDispositionType type, string?filename = null) { _request.ContentDisposition.Set(type, filename); return(this); }
/// <summary> /// Initializes a new instance of the <see cref="ContentDisposition"/> class. /// </summary> /// <param name="type">The type.</param> public ContentDisposition(ContentDispositionType type) { this.type = type; }
public void Reset() { _filename = null; _type = ContentDispositionType.Unknown; }