c# - Cast expression tree to void -


given expression tree inner, want wrap inside no-op expression of type void. expression inner should still evaluated, return type should thrown away. how do it?

if curious why want it, 1 possible application such casting expression.switch, requires expression.switchcase expressions return same type.

my current workaround cast type object wrapping inner this: expression.block(inner, expression.constant(null)). such solution seems weird, bulks code, , possibly complicates generated msil code too.

one option use the overload of expression.switch() lets specify return type. if specify void, expressions of type accepted cases. in overload, need specify defaultbody , comparison parameters, can make them null.

another option indeed use expression.block(), again the overload lets specify type. in case, like:

expression.block(typeof(void), inner) 

i don't expect have significant effect on generated il.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -