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:
- Parse(string) - Parse C# statement strings into IStatement objects
- FromExpression(IExpression) - Create expression statements from IExpression objects
- FromTemplate(TemplateInvocation, object?) and overloads - Create statements by invoking templates
- Block(params IStatement[]) and List(IEnumerable<IStatement>) - Create blocks and statement lists
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. |