Given some expression tree inner
, I want to wrap it inside no-op expression of type void
. Expression inner
should still be evaluated, but its return type should be thrown away. How do I do it?
If you are curious as to why I would want to do it, one possible application for such casting is Expression.Switch
, which requires all Expression.SwitchCase
expressions to return the same type.
My current workaround is to cast everything to type Object
by wrapping inner
like this: Expression.Block(inner, Expression.Constant(null))
. Such solution seems weird, bulks up my code, and possibly complicates the generated MSIL code too.