Interface IValueFormatter
- Namespace
- CSF.Screenplay.Reporting
- Assembly
- CSF.Screenplay.Abstractions.dll
An object which can format a value which appears within a Screenplay report.
public interface IValueFormatter
Remarks
Implement this interface in your own types in order to create a service which may externally format values for inclusion in a Screenplay report.
A typical Screenplay solution will include many implementations of this interface, each of which is responsible for formatting a specific subset of values. Before an implementation of this type is used to format a value, the CanFormat(object) method should be called in order to determine whether the formatter is suitable for the value in question. This is an application of the strategy pattern: https://en.wikipedia.org/wiki/Strategy_pattern. For any concrete implementation of this interface to be considered in formatting a value with a report, its type must first be registered with the IFormatterRegistry.
The FormatForReport(object) method should be used to create a human-readable string which represents the object in the report text. This interface is a part of the mechanism for formatting values in reports in Screenplay.
Methods
CanFormat(object)
Gets a value indicating whether this object is suitable for formatting the specified value.
bool CanFormat(object value)
Parameters
value
objectThe value to be formatted
Returns
FormatForReport(object)
Gets a formatted string which represents the specified value.
string FormatForReport(object value)
Parameters
value
objectThe 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.