HttpRangeParser<T> Class
Namespace: System.Net.Http.Headers
Overview
Represents a parser for the <code>Range</code> HTTP header.
Syntax
C#
public abstract class HttpRangeParser<T> : object
Type Parameters
- T
Description
The type of the items returned by the parser.
Constructors
HttpRangeParser()
Initializes a new instance of the
HttpRangeParser<T> class.
Methods
ParseRange(String, Int64)
Parses a range string into an array of
T objects.
Parameters
- range:
string - length:
long
Returns
T[]: An array of T objects representing the parsed range.
ParseRangeFrom(String)
Parses a range string that specifies only the start of the range.
Parameters
- range:
string
Returns
T: A T object representing the parsed range.
ParseRangeTo(String)
Parses a range string that specifies only the end of the range.
Parameters
- range:
string
Returns
T: A T object representing the parsed range.
Remarks
This class is abstract and must be implemented by a concrete derived class. For example, HttpHeaderParser<RangeItemHeaderValue> is used to parse the Range header.
Examples
Basic Usage
The following example shows how to parse a common Range header:
string rangeHeader = "bytes=0-499";
HttpRangeParser<RangeItemHeaderValue> parser = new RangeItemHeaderValue(); // Assuming a concrete implementation exists
RangeItemHeaderValue[] ranges = parser.ParseRange(rangeHeader, 1000); // Assuming total length is 1000
foreach (var range in ranges)
{
Console.WriteLine($"Start: {range.From}, End: {range.To}");
}