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
-
objectTemplate
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
literalLengthintThe total length of the literal parts.
formattedCountintThe 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
expressionExprThe expression.
AppendFormatted(Template)
Appends another template's parts. Called by the compiler for interpolated strings.
public void AppendFormatted(Template template)
Parameters
templateTemplateThe 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
valueboolThe value.
AppendFormatted(string?)
Appends a string hole as literal text. Called by the compiler for interpolated strings.
public void AppendFormatted(string? value)
Parameters
valuestringThe 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
valueTThe value.
Type Parameters
TThe value type.
AppendLiteral(string)
Appends literal text. Called by the compiler for interpolated strings.
public void AppendLiteral(string value)
Parameters
valuestringThe literal text.
Equals(Template?)
public bool Equals(Template? other)
Parameters
otherTemplate
Returns
- bool
Equals(object?)
public override bool Equals(object? obj)
Parameters
objobject
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
expressionExprThe expression.
Returns
implicit operator Template(bool)
Creates a template containing the literal text true or false.
public static implicit operator Template(bool value)
Parameters
valueboolThe value.
Returns
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
valuedoubleThe value.
Returns
implicit operator Template(string)
Creates a template containing only literal text.
public static implicit operator Template(string text)
Parameters
textstringThe text.