Class FormattableStringMessageWriter
- Namespace
- Ploch.CommandLine.Spectre.Output
- Assembly
- Ploch.CommandLine.Spectre.dll
Renders a FormattableString as interpolated markup: the template is parsed as Spectre markup, the string values in the holes are escaped rather than parsed (a value of another type is formatted and its text parsed as markup, as Spectre.Console does), and the holes are formatted with the caller's format provider.
public class FormattableStringMessageWriter : TypeMessageWriter<FormattableString>, IMessageWriter<FormattableString>, IMessageWriter, IMessageHandler
- Inheritance
-
FormattableStringMessageWriter
- Implements
- Inherited Members
Remarks
This is the writer Write<TMessage>(TMessage, IFormatProvider?) selects for a FormattableString, so
a consumer that registers its own IMessageWriter<TMessage> for that type through
AddMessageWriter<TMessageType, TWriter>(IServiceCollection) replaces it. The
holes are deliberately not run through the registered IMessageFormatter instances: the
formatters pre-render each argument to a string, which drops a format specifier such as {total:N2},
hides an argument from an ICustomFormatter supplied by the provider, and replaces an
exception's ToString() with the formatter's text. A writer that wants that behaviour can call
GetMessageText(FormattableString?, string?, IFormatProvider?) itself.
Constructors
- FormattableStringMessageWriter(IAnsiConsole)
Renders a FormattableString as interpolated markup: the template is parsed as Spectre markup, the string values in the holes are escaped rather than parsed (a value of another type is formatted and its text parsed as markup, as Spectre.Console does), and the holes are formatted with the caller's format provider.
Methods
- Write(FormattableString?, IMessageFormatterProcessor?, IFormatProvider?)
Writes a formattable string message to the output as interpolated markup.