Table of Contents

Class HumanizerFormatter

Namespace
CSF.Screenplay.Reporting
Assembly
CSF.Screenplay.dll

A formatter which makes use of the Humanizer: https://github.com/Humanizr/Humanizer library to format a limited number of value types.

public class HumanizerFormatter : IValueFormatter
Inheritance
HumanizerFormatter
Implements
Inherited Members

Remarks

In theory this formatter could do quite a lot more, as Humanizer's capabilities are much wider than the functionality used here. Since this is a preloaded/default formatter, it is intentionally limited so as to avoid accidentally "humanising" values which were already human-readable, mangling them in an unwanted way.

The types supported by this formatter implementation are:

TypeNote
DateTime Formatted by Humanizer
Nullable<T> of DateTimeFormatted by Humanizer if not null, otherwise CanFormat(object) will return false
TimeSpan Formatted by Humanizer
Nullable<T> of TimeSpanFormatted by Humanizer if not null, otherwise CanFormat(object) will return false
Implements IEnumerable<T> of stringFormatted by Humanizer into a comma-separated list

Developers are welcome to create their own formatter implementations which make use of Humanizer (the dependency is already present) and which more closely target the values they'd like formatted. This class is intentionally limited to formatting values which are unlikely to be controversial.

Methods

CanFormat(object)

Gets a value indicating whether this object is suitable for formatting the specified value.

public bool CanFormat(object value)

Parameters

value object

The value to be formatted

Returns

bool

true if this formatter is suitable for formatting the specified value; false if not.

FormatForReport(object)

Gets a formatted string which represents the specified value.

public string FormatForReport(object value)

Parameters

value object

The value to be formatted

Returns

string

A formatted string which represents the specified value.

Remarks

Ensure that the value has been tested with CanFormat(object) before executing this method. The behaviour of this method is undefined for any value for which the can-format method does not return true. It may lead to exceptions or garbage output.