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
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
TypeThe 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
TypeThe 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
TypeThe type of the object to deserialize.
readStream
StreamThe stream to read from.
content
HttpContentThe HTTP content.
formatterLogger
IFormatterLoggerThe 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
TypeThe type of the object to deserialize.
readStream
StreamThe stream to read from.
content
HttpContentThe HTTP content.
formatterLogger
IFormatterLoggerThe formatter logger for collecting errors.
cancellationToken
CancellationTokenA cancellation token to cancel the operation.