Table of Contents

Class TextMediaTypeFormatter

Namespace
Ecng.Net
Assembly
Ecng.Net.Clients.dll

A media type formatter for processing text-based content.

public class TextMediaTypeFormatter : MediaTypeFormatter
Inheritance
TextMediaTypeFormatter
Extension Methods

Constructors

TextMediaTypeFormatter(IEnumerable<string>)

Initializes a new instance of the TextMediaTypeFormatter class with the specified media types.

public TextMediaTypeFormatter(IEnumerable<string> mediaTypes)

Parameters

mediaTypes IEnumerable<string>

A collection of media type strings.

Exceptions

ArgumentNullException

Thrown when mediaTypes is null.

Methods

CanReadType(Type)

Determines whether the formatter can read objects of the specified type.

public override bool CanReadType(Type type)

Parameters

type Type

The type to test for read support.

Returns

bool

true if the type can be read; otherwise, false.

CanWriteType(Type)

Determines whether the formatter can write objects of the specified type.

public override bool CanWriteType(Type type)

Parameters

type Type

The type to test for write support.

Returns

bool

false as this formatter does not support writing.

ReadFromStreamAsync(Type, Stream, HttpContent, IFormatterLogger)

Asynchronously reads an object from the specified stream. This overload calls the overload with a cancellation token.

public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)

Parameters

type Type

The type of the object to deserialize.

readStream Stream

The stream to read from.

content HttpContent

The HTTP content.

formatterLogger IFormatterLogger

The formatter logger for collecting errors.

Returns

Task<object>

A task that represents the asynchronous read operation. The task result contains the deserialized object.

ReadFromStreamAsync(Type, Stream, HttpContent, IFormatterLogger, CancellationToken)

Asynchronously reads an object from the specified stream using the provided cancellation token.

public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger, CancellationToken cancellationToken)

Parameters

type Type

The type of the object to deserialize.

readStream Stream

The stream to read from.

content HttpContent

The HTTP content.

formatterLogger IFormatterLogger

The formatter logger for collecting errors.

cancellationToken CancellationToken

A cancellation token to cancel the operation.

Returns

Task<object>

A task that represents the asynchronous read operation. The task result contains the deserialized object.