Represents a conditional range request header value.
Conditional range requests allow a client to request only a portion of a resource.
This class is used in conjunction with the Range header to specify
conditions that must be met for the partial response to be sent.
The RangeConditionHeaderValue class supports two types of conditions:
This class is used by the Range property of the HttpRequestHeaders class.
Initializes a new instance of the RangeConditionHeaderValue class with a date.
Initializes a new instance of the RangeConditionHeaderValue class with an ETag.
Gets the date condition for the range request.
DateTimeOffset?
Gets a value indicating whether the Date property has a value.
bool
Gets the ETag condition for the range request.
string
Determines whether the specified object is equal to the current object.
Determines whether the specified RangeConditionHeaderValue object is equal to the current object.
Serves as the default hash function.
Parses a string into a RangeConditionHeaderValue instance.
Tries to parse a string into a RangeConditionHeaderValue instance.
Returns a string representation of the current object.
using System;
using System.Net.Http.Headers;
public class Example
{
public static void Main()
{
// Create a range condition header value based on an ETag
RangeConditionHeaderValue etagCondition = new RangeConditionHeaderValue("\"abcdef\"");
Console.WriteLine($"ETag Condition: {etagCondition}");
// Create a range condition header value based on a date
DateTimeOffset lastModified = new DateTimeOffset(2023, 10, 27, 10, 30, 0, TimeSpan.Zero);
RangeConditionHeaderValue dateCondition = new RangeConditionHeaderValue(lastModified);
Console.WriteLine($"Date Condition: {dateCondition}");
// Using TryParse
RangeConditionHeaderValue parsedCondition;
if (RangeConditionHeaderValue.TryParse("\"xyz123\"", out parsedCondition))
{
Console.WriteLine($"Successfully parsed: {parsedCondition}");
}
else
{
Console.WriteLine("Failed to parse.");
}
}
}