Open sandboxFocus

Class InterpolatedStringBuilder

Allows building run-time interpolated string expressions programmatically by adding text and expression parts.

Inheritance
InterpolatedStringBuilder
Namespace: Metalama.Framework.Code.SyntaxBuilders
Assembly: Metalama.Framework.dll
Syntax
[CompileTime]
public sealed class InterpolatedStringBuilder : INotNullExpressionBuilder, IExpressionBuilder
Remarks

InterpolatedStringBuilder provides a convenient way to generate run-time interpolated strings when the content is determined at compile time. Instead of using string.Format and building separate arrays of arguments, you can use AddText(string?) to add literal text and AddExpression(dynamic?, int?, string?) to add interpolated expressions with optional alignment and format specifiers.

After building the string content, call ToExpression() to get an IExpression representing the interpolated string. The generated code uses C# interpolated string syntax ($"...").

Constructors

Name Description
InterpolatedStringBuilder()

Properties

Name Description
ItemCount

Gets the number of items that have been added to the current builder.

Methods

Name Description
AddExpression(IExpression?, int?, string?)

Adds an expression to the interpolated string.

AddExpression(dynamic?, int?, string?)

Adds an expression to the interpolated string.

AddText(string?)

Adds a fixed text to the interpolated string.

Clone()

Returns a clone of the current InterpolatedStringBuilder.

ToExpression()

Creates a compile-time IExpression from the current InterpolatedStringBuilder.

Extension Methods

See Also