Represents a parameter value for an HTTP header. This class is typically used to represent the value of a single parameter within a header, such as the q value in a Accept header.
System.Net.Http.Headers
System.Net.Http.Formatting.dll
public class HttpParameterValue
The HttpParameterValue class provides a way to construct and manipulate parameter values that are commonly found in HTTP headers. It ensures that these values are correctly formatted and encoded according to HTTP specifications. This class is immutable, meaning once an instance is created, its value cannot be changed.
HttpParameterValue(string value)Initializes a new instance of the HttpParameterValue class with the specified string value.
public HttpParameterValue(string value);
| Name | Type | Description |
|---|---|---|
Value |
string |
Gets the string representation of the parameter value. |
Equals(object obj)Determines whether the specified object is equal to the current object.
public override bool Equals(object obj);
GetHashCode()Serves as the default hash function.
public override int GetHashCode();
ToString()Returns a string that represents the current object.
public override string ToString();
The following example demonstrates how to create and use HttpParameterValue to represent a quality factor (q) in an Accept header.
using System.Net.Http.Headers;
// Creating an HttpParameterValue for a quality factor of 0.7
HttpParameterValue qualityValue = new HttpParameterValue("0.7");
// Accessing the string value
string valueAsString = qualityValue.Value; // "0.7"
// You would typically use this with other header values, e.g., MediaWithQualityHeaderValue
// This is a simplified representation.
Console.WriteLine($"Parameter value: {qualityValue.ToString()}");
When constructing HttpParameterValue, the provided string will be used directly. It is the responsibility of the developer to ensure that the string value is valid for the intended HTTP header parameter.