private static int GetDispositionTypeLength(StringSegment input, int startIndex, out ContentDispositionHeaderValue parsedValue)
        {
            Contract.Requires(startIndex >= 0);

            parsedValue = null;

            if (StringSegment.IsNullOrEmpty(input) || (startIndex >= input.Length))
            {
                return(0);
            }

            // Caller must remove leading whitespaces. If not, we'll return 0.
            var dispositionTypeLength = GetDispositionTypeExpressionLength(input, startIndex, out var dispositionType);

            if (dispositionTypeLength == 0)
            {
                return(0);
            }

            var current = startIndex + dispositionTypeLength;

            current = current + HttpRuleParser.GetWhitespaceLength(input, current);
            var contentDispositionHeader = new ContentDispositionHeaderValue();

            contentDispositionHeader._dispositionType = dispositionType;

            // If we're not done and we have a parameter delimiter, then we have a list of parameters.
            if ((current < input.Length) && (input[current] == ';'))
            {
                current++; // skip delimiter.
                int parameterLength = NameValueHeaderValue.GetNameValueListLength(input, current, ';',
                                                                                  contentDispositionHeader.Parameters);

                parsedValue = contentDispositionHeader;
                return(current + parameterLength - startIndex);
            }

            // We have a ContentDisposition header without parameters.
            parsedValue = contentDispositionHeader;
            return(current - startIndex);
        }
        public static bool TryParse(StringSegment input, out ContentDispositionHeaderValue parsedValue)
        {
            var index = 0;

            return(Parser.TryParseValue(input, ref index, out parsedValue));
        }