title: Expression.Switch() struggling on case implementation
body: <p>I'm trying to implement the <code>Expression.Switch()</code> to create a switch statement within my expressions. I'm struggling with some issues.</p>
  
  <p>I've created a small example that raises the exception. The switch uses a string to switch the cases and within that case it will assign a variable.</p>
  
  <p>Here is some code that will raise the exception:</p>
  
  <pre><code>// an int variable
  var var1 = Expression.Parameter(typeof(int));
  // a string variable
  var var2 = Expression.Parameter(typeof(string));
  
  var cases = new[] 
  { 
      // the first case 'SwitchCaseValue1' should write the int value 1 into variable var1
      Expression.SwitchCase(Expression.Assign(var1, Expression.Constant(1)), Expression.Constant("SwitchCaseValue1")),
      // the second case 'SwitchCaseValue2' should write the string value 'Example' into variable var2 
      Expression.SwitchCase(Expression.Assign(var2, Expression.Constant("Example")), Expression.Constant("SwitchCaseValue2"))
  };
  
  Expression.Switch(Expression.Constant("SwitchValue"), cases);
  </code></pre>
  
  <p>This will raise this excepion: <code>All case bodies and the default body must have the same type.</code></p>
  
  <p>I think this refers to the <code>Assign</code> returning for case 1 an int and for case 2 a string. <strong>How can i return nothing?</strong></p>
  
  <hr>
  
  <p>If I change the <code>var2</code> to type int:</p>
  
  <pre><code>// an int variable
  var var1 = Expression.Parameter(typeof(int));
  // a string variable
  var var2 = Expression.Parameter(typeof(int));
  
  var cases = new[] 
  { 
      // the first case 'SwitchCaseValue1' should write the int value 1 into variable var1
      Expression.SwitchCase(Expression.Assign(var1, Expression.Constant(1)), Expression.Constant("SwitchCaseValue1")),
      // the second case 'SwitchCaseValue2' should write the string value 'Example' into variable var2 
      Expression.SwitchCase(Expression.Assign(var2, Expression.Constant(2)), Expression.Constant("SwitchCaseValue2"))
  };
  
  Expression.Switch(Expression.Constant("SwitchValue"), cases);
  </code></pre>
  
  <p>It raises exception: <code>Default body must be supplied if case bodies are not System.Void.</code></p>
  
  <p>So i changed: the last line to
  <code>Expression.Switch(Expression.Constant("SwitchValue"), Expression.Constant(0), cases);</code></p>
  
  <p><strong>This will compile. but is not what I'm looking for...</strong></p>
  
  <hr>
  
  <p><strong>Is there another way to fix this first solution without implementing extra code to return the same type?</strong></p>
  
  <p>I don't like solutions like selecting a meaningless return value, like:</p>
  
  <pre><code>// an int variable
  var var1 = Expression.Parameter(typeof(int));
  // a string variable
  var var2 = Expression.Parameter(typeof(string));
  
  var cases = new[] 
  { 
      // the first case 'SwitchCaseValue1' should write the int value 1 into variable var1
      Expression.SwitchCase(
          Expression.Block( 
              Expression.Assign(var1, Expression.Constant(1)), 
              // return a boolean
              Expression.Constant(true)), 
          Expression.Constant("SwitchCaseValue1")),
      // the second case 'SwitchCaseValue2' should write the string value 'Example' into variable var2 
      Expression.SwitchCase(
          Expression.Block( 
              Expression.Assign(var2, Expression.Constant("Example")), 
              // return a boolean
              Expression.Constant(true)), 
          Expression.Constant("SwitchCaseValue2"))
  };
  
  
  Expression.Switch(Expression.Constant("SwitchValue"), Expression.Constant(false), cases);
  </code></pre>
  
  <hr>
  
  <p>I understand the logic of Expressions and returning a value. But is there a way to avoid implementing meaningless code?</p>