Provides factory methods to create IStatement objects, which are compile-time representations of run-time C# statements.
Namespace: Metalama.Framework.Code.SyntaxBuilders
Assembly: Metalama.Framework.dll
Syntax
[CompileTime]
public static class StatementFactoryRemarks
The StatementFactory class provides multiple approaches to creating IStatement objects:
<ul><li><xref href="Metalama.Framework.Code.SyntaxBuilders.StatementFactory.Parse(System.String)" data-throw-if-not-resolved="false"></xref> - Parse C# statement strings into <xref href="Metalama.Framework.Code.SyntaxBuilders.IStatement" data-throw-if-not-resolved="false"></xref> objects</li><li><xref href="Metalama.Framework.Code.SyntaxBuilders.StatementFactory.FromExpression(Metalama.Framework.Code.IExpression)" data-throw-if-not-resolved="false"></xref> - Create expression statements from <xref href="Metalama.Framework.Code.IExpression" data-throw-if-not-resolved="false"></xref> objects</li><li><xref href="Metalama.Framework.Code.SyntaxBuilders.StatementFactory.FromTemplate(Metalama.Framework.Aspects.TemplateInvocation%2cSystem.Object)" data-throw-if-not-resolved="false"></xref> and overloads - Create statements by invoking templates</li><li><xref href="Metalama.Framework.Code.SyntaxBuilders.StatementFactory.Block(Metalama.Framework.Code.SyntaxBuilders.IStatement%5b%5d)" data-throw-if-not-resolved="false"></xref> and <xref href="Metalama.Framework.Code.SyntaxBuilders.StatementFactory.List(System.Collections.Generic.IEnumerable%7bMetalama.Framework.Code.SyntaxBuilders.IStatement%7d)" data-throw-if-not-resolved="false"></xref> - Create blocks and statement lists</li></ul>
For complex statements that need programmatic construction with indentation, use <xref href="Metalama.Framework.Code.SyntaxBuilders.StatementBuilder" data-throw-if-not-resolved="false"></xref> instead,
which provides a StringBuilder-like API with automatic indentation management.
</p>
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. |