Open sandboxFocus

Class StatementFactory

Provides factory methods to create IStatement objects, which are compile-time representations of run-time C# statements.

Inheritance
StatementFactory
Namespace: Metalama.Framework.Code.SyntaxBuilders
Assembly: Metalama.Framework.dll
Syntax
[CompileTime]
public static class StatementFactory
Remarks

The StatementFactory class provides multiple approaches to creating IStatement objects:

For complex statements that need programmatic construction with indentation, use StatementBuilder instead, which provides a StringBuilder-like API with automatic indentation management.

Methods

Name Description
Block(IStatementList)

Creates a block from an IStatementList.

Block(params IStatement[])

Creates a block statement (enclosed in braces) containing zero, one, or many statements.

Block(IEnumerable<IStatement>)

Creates a block composed of zero, one or many statements.

FromExpression(IExpression)

Creates an expression statement from an IExpression (e.g., a method invocation or assignment).

FromTemplate(TemplateInvocation, object?)

Creates an IStatement by invoking a template specified by a TemplateInvocation.

FromTemplate(string, ITemplateProvider, object?)

Creates an IStatement obtained by invoking a template specified by its name, an ITemplateProvider, and optional arguments.

FromTemplate(string, TemplateProvider, object?)

Creates an IStatement obtained by invoking a template specified by its name, a TemplateProvider, and optional arguments.

FromTemplate(string, object?)

Creates an IStatement obtained by invoking a template specified by its name and optional arguments.

List(params IStatement[])

Creates an IStatementList from a collection of statements.

List(IEnumerable<IStatement>)

Creates an IStatementList from a list of IStatement.

Parse(string)

Parses a string containing a C# statement and returns an IStatement, which can be inserted into run-time code using InsertStatement(IStatement).

UnwrapBlock(IStatement)

Extracts an IStatementList from a block statement, or creates a singleton list if the statement is not a block.

See Also