One option is to use the overload of Expression.Switch()
that lets you specify the return type. If you specify void
, then expressions of any type will be accepted as the cases. In this overload, you also need to specify the defaultBody
and comparison
parameters, but you can just make them null
.
Another option is indeed to use Expression.Block()
, but again the overload that lets you specify the type. In your case, that would be something like:
Expression.Block(typeof(void), inner)
I don't expect this to have any significant effect on the generated IL.