PragmaHeaderValue

Namespace: System.Net.Http.Headers

Assembly: System.Net.Http.Headers.dll

Summary

Represents a Pragma header value. The Pragma header is an extension header, which means it can be used for non-standard header information.

Syntax

public sealed class PragmaHeaderValue

Constructors

PragmaHeaderValue()

Initializes a new instance of the PragmaHeaderValue class.

PragmaHeaderValue(string name)

Initializes a new instance of the PragmaHeaderValue class with the specified Pragma header name.

Parameters

Name Type Description
name string The name of the Pragma header.

PragmaHeaderValue(string name, string value)

Initializes a new instance of the PragmaHeaderValue class with the specified Pragma header name and value.

Parameters

Name Type Description
name string The name of the Pragma header.
value string The value of the Pragma header.

Properties

Name  string

Gets the name of the Pragma header.

Value  string

Gets the value of the Pragma header.

Methods

ToString()  string

Returns the string representation of the current Pragma header value.

Parse(string input)PragmaHeaderValue

Parses a Pragma header value from the specified string.

Parameters

Name Type Description
input string A string that contains the value to parse.

Returns

A PragmaHeaderValue object.

TryParse(string input, [out PragmaHeaderValue] value)bool

Tries to parse a Pragma header value from the specified string.

Parameters

Name Type Description
input string A string that contains the value to parse.
value out PragmaHeaderValue When this method returns, contains the parsed PragmaHeaderValue object if the parsing succeeded, or null if it failed.

Returns

true if the string was parsed successfully; otherwise, false.

Example Usage

using System.Net.Http.Headers;

// Creating a Pragma header value
var pragma = new PragmaHeaderValue("no-cache");
Console.WriteLine(pragma.ToString()); // Output: no-cache

// Creating a Pragma header value with a specific value
var noStorePragma = new PragmaHeaderValue("cache-control", "no-store");
Console.WriteLine(noStorePragma.ToString()); // Output: cache-control=no-store

// Parsing a Pragma header value
string input = "my-custom-pragma=some-value";
if (PragmaHeaderValue.TryParse(input, out PragmaHeaderValue parsedPragma))
{
    Console.WriteLine($"Parsed Name: {parsedPragma.Name}");
    Console.WriteLine($"Parsed Value: {parsedPragma.Value}");
}
else
{
    Console.WriteLine("Failed to parse Pragma header value.");
}