/// <summary>
/// Parses a section of the stream that is known to be parameter data.
/// </summary>
/// <param name="parameters">
/// The header parameters of this section. "name" must be a valid key.
/// </param>
/// <param name="reader">
/// The StreamReader to read the data from
/// </param>
/// <returns>
/// The <see cref="ParameterPart"/> containing the parsed data (name, value).
/// </returns>
/// <exception cref="MultipartParseException">
/// thrown if unexpected data is found such as running out of stream before hitting the boundary.
/// </exception>
private ParameterPart ParseParameterPart(Dictionary <string, string> parameters, RebufferableBinaryReader reader)
{
// Our job is to get the actual "data" part of the parameter and construct
// an actual ParameterPart object with it. All we need to do is read data into a string
// untill we hit the boundary
var data = new StringBuilder();
string line = reader.ReadLine();
while (line != this.boundary && line != this.endBoundary)
{
if (line == null)
{
throw new MultipartParseException("Unexpected end of section");
}
data.Append(line);
line = reader.ReadLine();
}
if (line == this.endBoundary)
{
this.readEndBoundary = true;
}
// If we're here we've hit the boundary and have the data!
var part = new ParameterPart(parameters["name"], data.ToString());
return(part);
}