Table of Contents

Class ReportFragmentFormatter

Namespace
CSF.Screenplay
Assembly
CSF.Screenplay.dll

Default implementation of IFormatsReportFragment.

public class ReportFragmentFormatter : IFormatsReportFragment
Inheritance
ReportFragmentFormatter
Implements
Inherited Members

Constructors

ReportFragmentFormatter(IGetsReportFormat, IGetsValueFormatter)

Initializes a new instance of ReportFragmentFormatter.

public ReportFragmentFormatter(IGetsReportFormat formatCreator, IGetsValueFormatter formatterFactory)

Parameters

formatCreator IGetsReportFormat

A format creator which parses the original format string and values into a ReportFormat

formatterFactory IGetsValueFormatter

A factory for instances of IValueFormatter

Exceptions

ArgumentNullException

If any parameter is null.

Methods

Format(string, params object[])

Gets the formatted report fragment from the specified template and values.

public ReportFragment Format(string template, params object[] values)

Parameters

template string

A string template for the report fragment

values object[]

A collection of values associated with the report fragment

Returns

ReportFragment

A formatted report fragment

Examples

The following code will produce the final formatted string as noted below.

var p1 = "first";
var p2 = "second";
formatter.Format("The values are {p2} and {p1}", p1, p2);

// This will yield the result "The values are first and second"

Remarks

The template should be a human-readable string (localized if you wish) which would be recorded in a Screenplay report. This string may contain any number of placeholder markers which are indicated by some text enclosed within braces, such as {Name}. This functions in a slightly similar fashion to .NET logging: https://learn.microsoft.com/en-us/dotnet/core/extensions/logging?tabs=command-line#log-message-template or the Format(string, params object[]) method.

Importantly, the placeholders are identified by names, rather than numeric index, in the same way that logging template strings work. Placeholders do not support any kind of format or alignment syntax.

Developers are encouraged to choose meaningful names for their placeholders. The ReportFragment which is produced by this method will include the values associated with those placeholder names. This allows reporting infrastructure to work in a similar manner to the way in which structured logging is described in the article linked above. This provides a richer data model than simply a plain string.

See Also