A compile-time representation of a run-time expression, representing C# syntax that will be generated in transformed code.
Namespace: Metalama.Framework.Code
Assembly: Metalama.Framework.dll
Syntax
[CompileTime]
[InternalImplement]
[Hidden]
public interface IExpression : IHasTypeRemarks
In Metalama templates, IExpression objects are compile-time representations of C# syntax that will be generated
in the transformed code. These objects represent the syntax itself, not the evaluation result. For example, 1+1 and
2 are two different expressions even though they evaluate to the same value at run time.
IExpression objects are two-way convertible with dynamic:
<ul><li>When typed as <xref href="Metalama.Framework.Code.IExpression" data-throw-if-not-resolved="false"></xref>, expressions can be used in compile-time APIs that manipulate syntax</li><li>When accessed via the <xref href="Metalama.Framework.Code.IExpression.Value" data-throw-if-not-resolved="false"></xref> property (which returns <code>dynamic</code>), expressions can be used directly in template code as run-time expressions</li><li>A <code>dynamic</code> value from a template can be cast back to <xref href="Metalama.Framework.Code.IExpression" data-throw-if-not-resolved="false"></xref> to use it in compile-time APIs</li></ul></p>
To create expressions, use ExpressionFactory for common scenarios or ExpressionBuilder for programmatic construction. Note that IField, IProperty, and IParameter also implement IExpression, allowing fields and properties to be used directly as expressions.
Properties
| Name | Description |
|---|---|
| IsAssignable | Gets a value indicating whether the Value can be set. |
| Value | Gets syntax for the current IExpression. |