Docs · API reference · Verso.Abstractions

IDataFormatter Interface#

Formats runtime objects into cell outputs for display. Multiple formatters may be registered; the host selects the best match using SupportedTypes, Priority, and CanFormat(object, IFormatterContext).

public interface IDataFormatter : Verso.Abstractions.IExtension

Implements IExtension

Properties#

IsFallback Property#

Whether this formatter is a generic fallback rather than a specialized representation. Language kernels can skip fallback formatters when they have a richer native formatter for values not claimed by an extension.

bool IsFallback { get; }

Property Value#

System.Boolean

Priority Property#

Priority used to resolve conflicts when multiple formatters match the same value. Higher values take precedence.

int Priority { get; }

Property Value#

System.Int32

SupportedTypes Property#

The set of types this formatter can handle. The host uses this for fast pre-filtering before calling CanFormat(object, IFormatterContext).

System.Collections.Generic.IReadOnlyList<System.Type> SupportedTypes { get; }

Property Value#

System.Collections.Generic.IReadOnlyList<System.Type>

Methods#

CanFormat(object, IFormatterContext) Method#

Returns whether this formatter can produce output for the given value in the current context. When MimeType specifies a target representation, this method must return false unless FormatAsync(object, IFormatterContext) will emit it.

bool CanFormat(object value, Verso.Abstractions.IFormatterContext context);

Parameters#

value System.Object

The object to format.

context IFormatterContext

Formatter context providing MIME preferences and display options.

Returns#

System.Boolean
true if this formatter can handle the value; otherwise false.

FormatAsync(object, IFormatterContext) Method#

Formats the given value into a cell output suitable for display. The returned MIME type must match MimeType when the formatter claimed a MIME-constrained context in CanFormat(object, IFormatterContext).

System.Threading.Tasks.Task<Verso.Abstractions.CellOutput> FormatAsync(object value, Verso.Abstractions.IFormatterContext context);

Parameters#

value System.Object

The object to format.

context IFormatterContext

Formatter context providing MIME preferences and display options.

Returns#

System.Threading.Tasks.Task<CellOutput>
A cell output containing the formatted representation of the value.