コード例 #1
0
        /// <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);
        }
コード例 #2
0
ファイル: ContentTypeHeader.cs プロジェクト: wingcd/utnt
 /// <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();
 }
コード例 #3
0
ファイル: ConnectionHeader.cs プロジェクト: wingcd/utnt
 /// <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();
 }
コード例 #4
0
ファイル: ContentTypeHeader.cs プロジェクト: wingcd/utnt
 /// <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;
 }
コード例 #5
0
ファイル: ConnectionHeader.cs プロジェクト: wingcd/utnt
 /// <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;
 }