Skip to main content
Version: Preview (0.3.0-preview.205)

Interface IValueObjectFormatter<TValue>

Namespace: AdCodicem.ValueObjects
Assembly: AdCodicem.ValueObjects.Abstractions.dll

Declares that a value object formats itself, rather than deferring to its underlying value.

public interface IValueObjectFormatter<TValue>

Type Parameters​

TValue

Underlying value type.

Remarks​

Implementing this takes over formatting entirely, including the default format, so it must handle an empty or null format specifier. It is what gives a value object named formats: an IBAN printed in groups of four, or masked down to its last four characters. A type that also implements never calls this one: the string formatter answers everywhere.

The generated ToString(format, provider) calls it with a stack buffer, then with a pooled buffer twice as large each time it returns false, up to 1,048,576 characters, past which it throws a . A format the rule does not support is therefore refused by throwing that exception, not by returning false. On a value object, text equal to the value returns the string the value object holds, so formatting a value unchanged allocates nothing.

Methods​

TryFormatValue(in TValue, Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)​

Writes the formatted value into a destination buffer.

public static abstract bool TryFormatValue(in TValue value, Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)

Parameters​

value TValue

Value to format.

destination Span<char>

Buffer to write into.

charsWritten int

Characters written, when the buffer was large enough.

format ReadOnlySpan<char>

Format specifier, possibly empty.

provider IFormatProvider?

Format provider.

Returns​

bool

false when the destination was too small, as the framework expects.