Table of Contents

Class Template

Namespace
Invex.StructuredText.Expressions
Assembly
Invex.StructuredText.dll

A text value made of literal text and embedded expressions, such as a YAML scalar.

public sealed class Template
Inheritance
object
Template

Remarks

Build one from a plain string (literal text), from any Expr (an embedded expression), or from an interpolated string whose holes are expressions: $"{workflow}-{branch}". A printer wraps each embedded expression in the platform's expression delimiters, so no manual evaluate or concatenate step is needed.

Templates are immutable once built.

Constructors

Template(int, int)

Used by the compiler when an interpolated string is converted to a Template.

public Template(int literalLength, int formattedCount)

Parameters

literalLength int

The total length of the literal parts.

formattedCount int

The number of holes.

Properties

Expressions

The expressions embedded in this template, in order.

public IEnumerable<Expr> Expressions { get; }

Property Value

IEnumerable<Expr>

IsSingleExpression

true when this template is a single embedded expression with no literal text.

public bool IsSingleExpression { get; }

Property Value

bool

Parts

The parts of this template, in order.

public IReadOnlyList<TemplatePart> Parts { get; }

Property Value

IReadOnlyList<TemplatePart>

Methods

AppendFormatted(Expr)

Appends an embedded expression. Called by the compiler for interpolated strings.

public void AppendFormatted(Expr expression)

Parameters

expression Expr

The expression.

AppendFormatted(Template)

Appends another template's parts. Called by the compiler for interpolated strings.

public void AppendFormatted(Template template)

Parameters

template Template

The template to splice in.

AppendFormatted(bool)

Appends a boolean hole as the literal text true or false. Called by the compiler for interpolated strings.

public void AppendFormatted(bool value)

Parameters

value bool

The value.

AppendFormatted(string?)

Appends a string hole as literal text. Called by the compiler for interpolated strings.

public void AppendFormatted(string? value)

Parameters

value string

The text.

AppendFormatted<T>(T)

Appends a value hole as literal text formatted with the invariant culture. Called by the compiler for interpolated strings.

public void AppendFormatted<T>(T value) where T : IFormattable

Parameters

value T

The value.

Type Parameters

T

The value type.

AppendLiteral(string)

Appends literal text. Called by the compiler for interpolated strings.

public void AppendLiteral(string value)

Parameters

value string

The literal text.

Equals(Template?)

public bool Equals(Template? other)

Parameters

other Template

Returns

bool

Equals(object?)

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

GetHashCode()

public override int GetHashCode()

Returns

int

ToString()

Renders this template using a neutral expression syntax, for debugging and test output.

public override string ToString()

Returns

string

The rendered text.

Operators

implicit operator Template(Expr)

Creates a template containing a single embedded expression.

public static implicit operator Template(Expr expression)

Parameters

expression Expr

The expression.

Returns

Template

implicit operator Template(bool)

Creates a template containing the literal text true or false.

public static implicit operator Template(bool value)

Parameters

value bool

The value.

Returns

Template

implicit operator Template(double)

Creates a template containing a number as literal text, formatted with the invariant culture.

public static implicit operator Template(double value)

Parameters

value double

The value.

Returns

Template

implicit operator Template(string)

Creates a template containing only literal text.

public static implicit operator Template(string text)

Parameters

text string

The text.

Returns

Template