MediaTypeSegmentValue Class

Namespace: System.Net.Http.Headers
Assembly: System.Net.Http.dll
Represents a media type segment value.

Syntax

public sealed class MediaTypeSegmentValue

Description

This class represents a segment of a media type, which typically consists of a type and a subtype. For example, in "application/json", "application" is the type and "json" is the subtype. This class can also handle optional parameters associated with a media type segment.

Constructors

Constructor Description
MediaTypeSegmentValue() Initializes a new instance of the MediaTypeSegmentValue class.
MediaTypeSegmentValue(string value) Initializes a new instance of the MediaTypeSegmentValue class with the specified string value.

Properties

Property Description
Parameters Gets a collection of parameters that are associated with the media type segment.
Value Gets or sets the string representation of the media type segment.

Methods

Method Description
ToString() Returns the string representation of the media type segment.
Equals(object obj) Determines whether the specified object is equal to the current object.
GetHashCode() Serves as the default hash function.

Remarks

The MediaTypeSegmentValue class is used internally by the MediaTypeHeaderValue class to represent individual segments of a media type. Each segment can have its own set of parameters.

This class is typically not instantiated directly by application developers. Instead, it is used when parsing and manipulating media type headers.

Example

// This is a conceptual example as MediaTypeSegmentValue is often used internally. // You would typically parse a full MediaTypeHeaderValue. // Assume we have a MediaTypeHeaderValue: "application/json; charset=utf-8" // The MediaTypeHeaderValue would internally use MediaTypeSegmentValue for "application/json". // To get the parameters associated with the media type segment: // var mediaType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); // foreach (var parameter in mediaType.Parameters) // { // Console.WriteLine($"{parameter.Name}: {parameter.Value}"); // } // This would output: // charset: utf-8