Table of Contents

Interface IOutputWriter

Namespace
HoofMark.CSharpTemplating.Abstractions
Assembly
HoofMark.CSharpTemplating.Abstractions.dll

A fluent, indentation-aware writer for building text file content. Returned by WriteFile(string, Action<IOutputWriter>).

public interface IOutputWriter

Remarks

All methods return this to allow fluent chaining:

context.WriteFile("Order.cs", w => w
    .WriteLine("namespace MyApp")
    .WriteLine("{")
    .Indent()
        .WriteLine("public class Order")
        .WriteLine("{")
        .Indent()
            .WriteLine("public int Id { get; set; }")
        .Dedent()
        .WriteLine("}")
    .Dedent()
    .WriteLine("}"));

Or using Block(string, Action<IOutputWriter>, bool) for automatic brace + indentation management:

context.WriteFile("Order.cs", w => w
    .WriteLine("namespace MyApp")
    .Block("public class Order", body => body
        .WriteLine("public int Id { get; set; }")
        .WriteLine("public decimal Total { get; set; }")));

Properties

IndentLevel

Current indentation level (zero-based number of indent units).

int IndentLevel { get; }

Property Value

int

Methods

Block(string, Action<IOutputWriter>, bool)

Writes a block: the header line, an opening brace, an indented body, and a closing brace.

IOutputWriter Block(string header, Action<IOutputWriter> body, bool trailingSemicolon = false)

Parameters

header string

The line before the opening brace, e.g. "public class Order".

body Action<IOutputWriter>

An action that writes the indented body content.

trailingSemicolon bool

If true, appends a semicolon after the closing brace (useful for namespace-scoped blocks in some languages, or struct initialisers).

Returns

IOutputWriter

Dedent(int)

Decreases the indentation level by levels (default 1). Indentation will not go below zero.

IOutputWriter Dedent(int levels = 1)

Parameters

levels int

Returns

IOutputWriter

Indent(int)

Increases the indentation level by levels (default 1). Each level adds one indentation unit (4 spaces by default; configurable via engine settings).

IOutputWriter Indent(int levels = 1)

Parameters

levels int

Returns

IOutputWriter

ToString()

Returns the full text that has been written so far.

string ToString()

Returns

string

Write(string)

Writes text at the current position without a trailing newline. If this is the first content on a new line, the current indentation is prepended.

IOutputWriter Write(string text)

Parameters

text string

Returns

IOutputWriter

WriteLine(string)

Writes text followed by a newline. If text is empty (the default), writes a blank line. The current indentation is prepended if this is the start of a line.

IOutputWriter WriteLine(string text = "")

Parameters

text string

Returns

IOutputWriter