A compile-time representation of a run-time object creation expression.
Namespace: Metalama.Framework.Code
Assembly: Metalama.Framework.dll
Syntax
[CompileTime]
[InternalImplement]
[Hidden]
public interface IObjectCreationExpression : IExpression, IHasTypeRemarks
The main use case for this interface is to add object initializers to constructor invocation expressions created via CreateInvokeExpression(). Use the WithObjectInitializer(params (IFieldOrProperty FieldOrProperty, IExpression Value)[]) or WithObjectInitializer(params (string FieldOrPropertyName, IExpression Value)[]) methods to specify the fields or properties to initialize.
For example, to create a new MyClass() { Field = 42, Property = "value" } expression:
var expr = constructor.CreateInvokeExpression()
.WithObjectInitializer(
(fieldDeclaration, ExpressionFactory.Literal(42)),
(propertyDeclaration, ExpressionFactory.Literal("value")));Methods
| Name | Description |
|---|---|
| WithObjectInitializer(params (IFieldOrProperty FieldOrProperty, IExpression Value)[]) | |
| WithObjectInitializer(params (string FieldOrPropertyName, IExpression Value)[]) |