Table of Contents

Interface IWriteStrategy

Namespace
Existential
Assembly
Existential.Net.dll

Represents a string writing strategy. Implementations of this interface can provide different strategies for writing text, such as writing to a console, a file, or a network stream.

public interface IWriteStrategy
Extension Methods

Examples

As there could be a wide variety of desired implementations of IWriteStrategy, no default implementations are provided. However, dependent on requirements, the methods can be very simple to implement, such as this example:

public void Write(string? inText) => Trace.TraceError(inText);
Tip

For .NET Core, a default implementation of the WriteLine(String) method is provided which calls the Write(String) method, so a separate implementation of WriteLine(String) may not need to be provided.

Remarks

MultiTextWriter can be constructed with a collection of implementations of IWriteStrategy to allow the same message to be written to multiple outputs.

Methods

Write(String)

Writes the provided text string to the chosen output medium.

void Write(string inText)

Parameters

inText System.String

The text string to write. Can be null.

Remarks

The specific behavior of this method depends on the implementation of the IWriteStrategy interface. For example, it could write to a console, a file, or a network stream.

WriteLine(String)

Writes the provided text string followed by a new line to the chosen output medium.

void WriteLine(string inText)

Parameters

inText System.String

The text string to write. Can be null.

Remarks

For .NET Core 3.0 or greater, a default implementation of this method is provided which calls the Write(String) method, and so a concrete implementation may not need to be provided.

See Also