Table of Contents

Class CodeGenerationVisitor

Namespace
LinqToDB.CodeModel
Assembly
linq2db.Tools.dll

Base code generation visitor that contains public API for code generation.

public abstract class CodeGenerationVisitor : CodeModelVisitor
Inheritance
CodeGenerationVisitor
Inherited Members
Extension Methods

Constructors

CodeGenerationVisitor(string, string)

Constructor.

protected CodeGenerationVisitor(string newLine, string indent)

Parameters

newLine string

Sequence of characters, used as new line by code writer.

indent string

Sequence of characters, used as one level of indent.

Properties

NewLineSequences

Character sequences, recognized by specific language as new line sequences.

protected abstract string[] NewLineSequences { get; }

Property Value

string[]

Methods

BuildFragment(Action)

Executes provided action and returns all code, generated by it.

protected string BuildFragment(Action fragmentBuilder)

Parameters

fragmentBuilder Action

Code generation action.

Returns

string

Code, generated by fragmentBuilder.

DecreaseIdent()

Decreases current indent size by one level. Throws exception if indent level goes below zero.

protected void DecreaseIdent()

GetResult()

Gets all code, generated by code generator.

public string GetResult()

Returns

string

IncreaseIdent()

Increases current indent size by one level.

protected void IncreaseIdent()

PadWithSpaces(string, int)

Emits specified code fragment and append spaces after it to match specified by fullLength length (if fragment length is smaller than fullLength).

protected void PadWithSpaces(string text, int fullLength)

Parameters

text string

Code fragment to write.

fullLength int

Minimal length of emitted string.

SplitByNewLine(string)

Splits provided text into fragments (lines) using language-specific new line detection logic.

protected string[] SplitByNewLine(string text)

Parameters

text string

Text to split into lines.

Returns

string[]

Array of lines (without terminating newline sequences).

UndoTrivia(IEnumerable<SimpleTrivia>?)

Undo trivia.

protected void UndoTrivia(IEnumerable<SimpleTrivia>? trivia)

Parameters

trivia IEnumerable<SimpleTrivia>

Write(char)

Emits provided character into generated code as-is. Prepends it with indent if needed.

protected void Write(char chr)

Parameters

chr char

Single character to write to code generator.

Write(string)

Emits provided code fragment into generated code as-is. Prepends fragment with indent if needed (only before first line if multiple lines passed).

protected void Write(string text)

Parameters

text string

Code fragment to write to code generator.

WriteDelimitedList<T>(IEnumerable<T>, Action<T>, string, bool)

Generates code for provided code elements with specified delimiter between elements.

protected void WriteDelimitedList<T>(IEnumerable<T> items, Action<T> writer, string delimiter, bool newLine)

Parameters

items IEnumerable<T>

Code elements to convert to code.

writer Action<T>

Custom element code generation action.

delimiter string

Sequence of characters used as delimiter between code elements.

newLine bool

Specify wether method should generate new line sequence after each delimiter. Also when true, adds new line sequence after last element (without delimiter).

Type Parameters

T

Code element type.

WriteDelimitedList<T>(IEnumerable<T>, string, bool)

Generates code for provided code elements with specified delimiter between elements.

protected void WriteDelimitedList<T>(IEnumerable<T> items, string delimiter, bool newLine) where T : ICodeElement

Parameters

items IEnumerable<T>

Code elements to convert to code.

delimiter string

Sequence of characters used as delimiter between code elements.

newLine bool

Specify wether method should generate new line sequence after each delimiter. Also when true, adds new line sequence after last element (without delimiter).

Type Parameters

T

Code element type.

WriteLine()

Emits new line. Does not prepend new line with indent if it is missing.

protected void WriteLine()

WriteLine(char)

Emits provided character into generated code as-is and then emits new line. Prepends it with indent if needed (only before first line if multiple lines passed).

protected void WriteLine(char chr)

Parameters

chr char

Single character to write to code generator.

WriteLine(string)

Emits provided code fragment into generated code as-is and then emits new line. Prepends fragment with indent if needed (only before first line if multiple lines passed).

protected void WriteLine(string text)

Parameters

text string

Code fragment to write to code generator.

WriteNewLineDelimitedList<T>(IEnumerable<T>)

Generates code for provided code elements with new line between elements. In comparison to WriteDelimitedList<T>(IEnumerable<T>, Action<T>, string, bool) doesn't add new line sequence after last element.

protected void WriteNewLineDelimitedList<T>(IEnumerable<T> items) where T : ICodeElement

Parameters

items IEnumerable<T>

Code elements to convert to code.

Type Parameters

T

Code element type.

WriteTrivia(IEnumerable<SimpleTrivia>?)

Emits trivia.

protected void WriteTrivia(IEnumerable<SimpleTrivia>? trivia)

Parameters

trivia IEnumerable<SimpleTrivia>

WriteUnindented(string)

Emits provided code fragment into generated code as-is without automatic indent generation.

protected void WriteUnindented(string text)

Parameters

text string

Code fragment to write to code generator.

WriteUnindentedLine(string)

Emits provided code fragment into generated code as-is without automatic indent generation and then emits new line sequence.

protected void WriteUnindentedLine(string text)

Parameters

text string

Code fragment to write to code generator.

WriteXmlAttribute(string, bool)

Emits provided code fragment and escape characters using XML escaping rules for attributes. Note that attribute should use " as quotation mark.

protected void WriteXmlAttribute(string text, bool doubleQuote = true)

Parameters

text string

Code fragment to write.

doubleQuote bool

Attribute use " as quotation mark. Otherwise ' used.

WriteXmlText(string)

Emits provided code fragment and escape characters using XML escaping rules for inner text.

protected void WriteXmlText(string text)

Parameters

text string

Code fragment to write.