Table of Contents

Class SourceWriter

Namespace
PolyType.Roslyn
Assembly
PolyType.Roslyn.dll

A utility class for generating indented source code.

public sealed class SourceWriter : IDisposable
Inheritance
SourceWriter
Implements
Inherited Members

Constructors

SourceWriter(char, int, int)

Creates a new instance of SourceWriter with the specified indentation settings.

public SourceWriter(char indentationChar, int charsPerIndentation, int capacity = 1024)

Parameters

indentationChar char

The indentation character to be used.

charsPerIndentation int

The number of characters per indentation to be applied.

capacity int

The initial capacity of the buffer.

SourceWriter(int)

Creates a new instance of SourceWriter.

public SourceWriter(int capacity = 1024)

Parameters

capacity int

The initial capacity of the buffer.

Properties

CharsPerIndentation

Gets the number of characters per indentation.

public int CharsPerIndentation { get; }

Property Value

int

Indentation

Gets or sets the current indentation level.

public int Indentation { get; set; }

Property Value

int

IndentationChar

Gets the character used for indentation.

public char IndentationChar { get; }

Property Value

char

Length

Gets the length of the generated source text.

public int Length { get; }

Property Value

int

Methods

Dispose()

Disposes the SourceWriter and returns buffers to the pool.

public void Dispose()

ToSourceText()

Encodes the currently written source to a SourceText instance.

public SourceText ToSourceText()

Returns

SourceText

ToString()

Renders the written text as a string.

public override string ToString()

Returns

string

WriteLine()

Appends a new line to the source text.

public void WriteLine()

WriteLine(ref WriteLineInterpolatedStringHandler)

Appends a new line with the specified interpolated string.

public void WriteLine(ref SourceWriter.WriteLineInterpolatedStringHandler handler)

Parameters

handler SourceWriter.WriteLineInterpolatedStringHandler

The interpolated string handler.

WriteLine(char)

Appends a new line with the current character.

public void WriteLine(char value)

Parameters

value char

WriteLine(string, bool, bool)

Appends a new line with the specified text.

public void WriteLine(string text, bool trimDefaultAssignmentLines = false, bool disableIndentation = false)

Parameters

text string

The text to append.

trimDefaultAssignmentLines bool

Trims any lines containing 'Identifier = null', 'Identifier = false', or 'Identifier = default' assignments.

disableIndentation bool

Append text without preserving the current indentation.