Allows building run-time array creation expressions programmatically by adding items one at a time.
Namespace: Metalama.Framework.Code.SyntaxBuilders
Assembly: Metalama.Framework.dll
Syntax
[CompileTime]
public sealed class ArrayBuilder : INotNullExpressionBuilder, IExpressionBuilderRemarks
ArrayBuilder provides a convenient way to generate run-time arrays when the number of elements or their values are determined at compile time. Instead of generating array initialization code as text, you can add items programmatically using Add(dynamic?), then call ToExpression() to get an IExpression representing the array creation expression.
This is particularly useful when you need to generate arrays as method arguments or in other expression contexts where a single expression is required. The generated code uses C# array initializer syntax.
Constructors
| Name | Description |
|---|---|
| ArrayBuilder() | Initializes a new instance of the ArrayBuilder class where the item type is a object. |
| ArrayBuilder(IType) | Initializes a new instance of the ArrayBuilder class where the item type is a given IType. |
| ArrayBuilder(Type) | Initializes a new instance of the ArrayBuilder class where the item type is a given Type. |
Methods
| Name | Description |
|---|---|
| Add(IExpression) | Adds an item to the array. |
| Add(dynamic?) | Adds an item to the array. |
| Clone() | Returns a clone of the current ArrayBuilder. |
| ToExpression() | Creates a compile-time IExpression representing the array from the current ArrayBuilder. |