Search code examples
c#.netlinqexpression-trees

Expression.Body.Expressions -- how to use it?


This is what I can see in the QuickView window: enter image description here I want to use the Expressions property in my code, but it is not accessible: enter image description here Does anyone know how to use this Expressions property in code?


Solution

  • The compile-time type of expression.Body is Expression. No such property exists.

    The runtime type of expression.Body appears to be a NewArrayInitExpression. That type has the Expressions property that you're looking for.

    You need to cast it to the appropriate type to be able to access the appropriate property. The closest accessible type is NewArrayExpression.

    var expressions = ((NewArrayExpression)expression.Body).Expressions;