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:
- When typed as IExpression, expressions can be used in compile-time APIs that manipulate syntax
- When accessed via the Value property (which returns
dynamic), expressions can be used directly in template code as run-time expressions - A
dynamicvalue from a template can be cast back to IExpression to use it in compile-time APIs
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. |