/// <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); }
/// <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="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; }