/// <summary>
        /// Parse parameters.
        /// </summary>
        /// <param name="reader">Parser containing buffer to parse.</param>
        /// <param name="delimiter">Parameter delimiter</param>
        /// <returns>A collection with all parameters (or just a empty collection).</returns>
        /// <exception cref="FormatException">Expected a value after equal sign.</exception>
        public static HeaderParameterCollection Parse(ITextReader reader, char delimiter)
        {
            if (reader.Current == delimiter)
                reader.Consume();
            reader.ConsumeWhiteSpaces();

            var collection = new HeaderParameterCollection();
            string name = reader.ReadToEnd("=" + delimiter);
            while (name != string.Empty && !reader.EOF)
            {
                // got a parameter value
                if (reader.Current == '=')
                {
                    reader.ConsumeWhiteSpaces('=');

                    string value = reader.Current == '"'
                                       ? reader.ReadQuotedString()
                                       : reader.ReadToEnd(delimiter);

                    reader.ConsumeWhiteSpaces();
                    if (value == string.Empty && reader.Current != delimiter)
                        throw new FormatException("Expected a value after equal sign.");

                    collection.Add(name, value);
                }
                else // got no value
                {
                    collection.Add(name, string.Empty);
                }

                reader.ConsumeWhiteSpaces(delimiter); // consume delimiter and white spaces
                name = reader.ReadToEnd("=" + delimiter);
            }
            return collection;
        }
        /// <summary>
        /// Parse parameters.
        /// </summary>
        /// <param name="reader">Parser containing buffer to parse.</param>
        /// <param name="delimiter">Parameter delimiter</param>
        /// <returns>A collection with all parameters (or just a empty collection).</returns>
        /// <exception cref="FormatException">Expected a value after equal sign.</exception>
        public static HeaderParameterCollection Parse(ITextReader reader, char delimiter)
        {
            if (reader.Current == delimiter)
            {
                reader.Consume();
            }
            reader.ConsumeWhiteSpaces();

            var    collection = new HeaderParameterCollection();
            string name       = reader.ReadToEnd("=" + delimiter);

            while (name != string.Empty && !reader.EOF)
            {
                // got a parameter value
                if (reader.Current == '=')
                {
                    reader.ConsumeWhiteSpaces('=');

                    string value = reader.Current == '"'
                                       ? reader.ReadQuotedString()
                                       : reader.ReadToEnd(delimiter);

                    reader.ConsumeWhiteSpaces();
                    if (value == string.Empty && reader.Current != delimiter)
                    {
                        throw new FormatException("Expected a value after equal sign.");
                    }

                    collection.Add(name, value);
                }
                else // got no value
                {
                    collection.Add(name, string.Empty);
                }

                reader.ConsumeWhiteSpaces(delimiter); // consume delimiter and white spaces
                name = reader.ReadToEnd("=" + delimiter);
            }
            return(collection);
        }
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConnectionHeader"/> class.
 /// </summary>
 /// <param name="type">The type.</param>
 public ConnectionHeader(ConnectionType type)
 {
     Type       = type;
     Parameters = new HeaderParameterCollection();
 }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConnectionHeader"/> class.
 /// </summary>
 /// <param name="type">Connection type.</param>
 /// <param name="parameters">The parameters.</param>
 public ConnectionHeader(ConnectionType type, HeaderParameterCollection parameters)
 {
     Parameters = parameters;
     Type       = type;
 }
Beispiel #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ContentTypeHeader"/> class.
 /// </summary>
 /// <param name="contentType">Type of the content.</param>
 public ContentTypeHeader(string contentType)
 {
     Value       = contentType;
     _parameters = new HeaderParameterCollection();
 }
Beispiel #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ContentTypeHeader"/> class.
 /// </summary>
 /// <param name="contentType">Type of the content.</param>
 /// <param name="parameterCollection">Value parameters.</param>
 public ContentTypeHeader(string contentType, HeaderParameterCollection parameterCollection)
 {
     Value       = contentType;
     _parameters = parameterCollection;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConnectionHeader"/> class.
 /// </summary>
 /// <param name="type">Connection type.</param>
 /// <param name="parameters">The parameters.</param>
 public ConnectionHeader(ConnectionType type, HeaderParameterCollection parameters)
 {
     Parameters = parameters;
     Type = type;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConnectionHeader"/> class.
 /// </summary>
 /// <param name="type">The type.</param>
 public ConnectionHeader(ConnectionType type)
 {
     Type = type;
     Parameters = new HeaderParameterCollection();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ContentTypeHeader"/> class.
 /// </summary>
 /// <param name="contentType">Type of the content.</param>
 public ContentTypeHeader(string contentType)
 {
     Value = contentType;
     _parameters = new HeaderParameterCollection();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ContentTypeHeader"/> class.
 /// </summary>
 /// <param name="contentType">Type of the content.</param>
 /// <param name="parameterCollection">Value parameters.</param>
 public ContentTypeHeader(string contentType, HeaderParameterCollection parameterCollection)
 {
     Value = contentType;
     _parameters = parameterCollection;
 }