Expression
Gets the receiver expression written at the site, for inspection only, or null when the intercepted method is static or the
receiver is implicit. For a classic extension method called in reduced form, the receiver is the first element of
Arguments, and this property is null. For a conditional access a?.M(), it is the
expression a. For a method-reference site obj.M, it is obj, which C# evaluates when the delegate is created.
Declaration
IExpression? Expression { get; }Property Value
| Type | Description |
|---|---|
| IExpression |
Remarks
The value is an ISourceExpression. Its type and its constant value can be read. The Roslyn syntax is available through
the SDK method SourceExpressionExtensions.GetSourceSyntax. The expression cannot be emitted in generated code (LAMA0297), because
the site already evaluates it. The type of the expression is the type of the written receiver, which differs from Type in a
conditional access: in a?.M() with a nullable value type, a has the nullable type.