Class TextMediaTypeFormatter
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
mediaTypesIEnumerable<string>A collection of media type strings.
Exceptions
- ArgumentNullException
Thrown when
mediaTypesis null.
Methods
CanReadType(Type)
Determines whether the formatter can read objects of the specified type.
public override bool CanReadType(Type type)
Parameters
typeTypeThe type to test for read support.
Returns
- bool
trueif 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
typeTypeThe type to test for write support.
Returns
- bool
falseas 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
typeTypeThe type of the object to deserialize.
readStreamStreamThe stream to read from.
contentHttpContentThe HTTP content.
formatterLoggerIFormatterLoggerThe 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
typeTypeThe type of the object to deserialize.
readStreamStreamThe stream to read from.
contentHttpContentThe HTTP content.
formatterLoggerIFormatterLoggerThe formatter logger for collecting errors.
cancellationTokenCancellationTokenA cancellation token to cancel the operation.