MediaType Struct

A media type value.

Namespace
Microsoft.AspNetCore.Mvc.Formatters
Assemblies
  • Microsoft.AspNetCore.Mvc.Core

Syntax

public struct MediaType
struct Microsoft.AspNetCore.Mvc.Formatters.MediaType

Constructors

MediaType(Microsoft.Extensions.Primitives.StringSegment)

Initializes a Microsoft.AspNetCore.Mvc.Formatters.MediaType instance.

Arguments:mediaType (Microsoft.Extensions.Primitives.StringSegment) – The Microsoft.Extensions.Primitives.StringSegment with the media type.
public MediaType(StringSegment mediaType)
MediaType(System.String)

Initializes a Microsoft.AspNetCore.Mvc.Formatters.MediaType instance.

Arguments:mediaType (System.String) – The System.String with the media type.
public MediaType(string mediaType)
MediaType(System.String, System.Int32, System.Nullable<System.Int32>)

Initializes a Microsoft.AspNetCore.Mvc.Formatters.MediaType.MediaTypeParameterParser instance.

Arguments:
  • mediaType (System.String) – The System.String with the media type.
  • offset (System.Int32) – The offset in the <em>mediaType</em> where the parsing starts.
  • length (System.Nullable<System.Int32>) – The of the media type to parse if provided.
public MediaType(string mediaType, int offset, int ? length)

Properties

Microsoft.AspNetCore.Mvc.Formatters.MediaType.Charset

Gets the charset parameter of the Microsoft.AspNetCore.Mvc.Formatters.MediaType if it has one.

Return type:Microsoft.Extensions.Primitives.StringSegment
public StringSegment Charset { get; }
Microsoft.AspNetCore.Mvc.Formatters.MediaType.Encoding

Gets the System.Text.Encoding of the Microsoft.AspNetCore.Mvc.Formatters.MediaType if it has one.

Return type:System.Text.Encoding
public Encoding Encoding { get; }
Microsoft.AspNetCore.Mvc.Formatters.MediaType.MatchesAllSubTypes

Gets whether this Microsoft.AspNetCore.Mvc.Formatters.MediaType matches all subtypes.

Return type:System.Boolean
public bool MatchesAllSubTypes { get; }
Microsoft.AspNetCore.Mvc.Formatters.MediaType.MatchesAllTypes

Gets whether this Microsoft.AspNetCore.Mvc.Formatters.MediaType matches all types.

Return type:System.Boolean
public bool MatchesAllTypes { get; }
Microsoft.AspNetCore.Mvc.Formatters.MediaType.SubType

Gets the subtype of the Microsoft.AspNetCore.Mvc.Formatters.MediaType.

Return type:Microsoft.Extensions.Primitives.StringSegment
public StringSegment SubType { get; }
Microsoft.AspNetCore.Mvc.Formatters.MediaType.Type

Gets the type of the Microsoft.AspNetCore.Mvc.Formatters.MediaType.

Return type:Microsoft.Extensions.Primitives.StringSegment
public StringSegment Type { get; }

Methods

CreateMediaTypeSegmentWithQuality(System.String, System.Int32)

Creates an Microsoft.AspNetCore.Mvc.Formatters.Internal.MediaTypeSegmentWithQuality containing the media type in <em>mediaType</em> and its associated quality.

Arguments:
  • mediaType (System.String) – The media type to parse.
  • start (System.Int32) – The position at which the parsing starts.
Return type:

Microsoft.AspNetCore.Mvc.Formatters.Internal.MediaTypeSegmentWithQuality

Returns:

The parsed media type with its associated quality.

public static MediaTypeSegmentWithQuality CreateMediaTypeSegmentWithQuality(string mediaType, int start)
GetEncoding(Microsoft.Extensions.Primitives.StringSegment)
Return type:System.Text.Encoding
public static Encoding GetEncoding(StringSegment mediaType)
GetEncoding(System.String)
Return type:System.Text.Encoding
public static Encoding GetEncoding(string mediaType)
GetParameter(Microsoft.Extensions.Primitives.StringSegment)

Gets the parameter <em>parameterName</em> of the media type.

Arguments:parameterName (Microsoft.Extensions.Primitives.StringSegment) – The name of the parameter to retrieve.
Return type:Microsoft.Extensions.Primitives.StringSegment
Returns:The Microsoft.Extensions.Primitives.StringSegmentfor the given <em>parameterName</em> if found; otherwise<pre><code>null</code></pre>.
public StringSegment GetParameter(StringSegment parameterName)
GetParameter(System.String)

Gets the parameter <em>parameterName</em> of the media type.

Arguments:parameterName (System.String) – The name of the parameter to retrieve.
Return type:Microsoft.Extensions.Primitives.StringSegment
Returns:The Microsoft.Extensions.Primitives.StringSegmentfor the given <em>parameterName</em> if found; otherwise<pre><code>null</code></pre>.
public StringSegment GetParameter(string parameterName)
IsSubsetOf(Microsoft.AspNetCore.Mvc.Formatters.MediaType)

Determines whether the current Microsoft.AspNetCore.Mvc.Formatters.MediaType is a subset of the <em>set</em> Microsoft.AspNetCore.Mvc.Formatters.MediaType.

Arguments:set (Microsoft.AspNetCore.Mvc.Formatters.MediaType) – The set Microsoft.AspNetCore.Mvc.Formatters.MediaType.
Return type:System.Boolean
Returns:<pre><code>true</code></pre> if this Microsoft.AspNetCore.Mvc.Formatters.MediaType is a subset of <em>set</em>; otherwise<pre><code>false</code></pre>.
public bool IsSubsetOf(MediaType set)
ReplaceEncoding(Microsoft.Extensions.Primitives.StringSegment, System.Text.Encoding)

Replaces the encoding of the given <em>mediaType</em> with the provided <em>encoding</em>.

Arguments:
Return type:

System.String

Returns:

A media type with the replaced encoding.

public static string ReplaceEncoding(StringSegment mediaType, Encoding encoding)
ReplaceEncoding(System.String, System.Text.Encoding)

Replaces the encoding of the given <em>mediaType</em> with the provided <em>encoding</em>.

Arguments:
  • mediaType (System.String) – The media type whose encoding will be replaced.
  • encoding (System.Text.Encoding) – The encoding that will replace the encoding in the <em>mediaType</em>
Return type:

System.String

Returns:

A media type with the replaced encoding.

public static string ReplaceEncoding(string mediaType, Encoding encoding)