icsharpcode/ILSpy — Issue #316: Switch not Handling Goto Case XXX
Author: jcdickinson
Created: 2012-02-18 23:35:26+00:00
State: open

The switch/case logic is not handling `goto case ...`; instead either complicated `if`s are generated or a bunch of labels and `goto`s are generated after the `switch`.

Set of `if`s:

```csharp
string test = "hello";

switch (test)
{
case "hello":
Console.WriteLine("Foo");
goto case "bar";
case "bar":
Console.WriteLine("Bar");
break;
case "baz":
Console.WriteLine("Bar");
break;
case "frob":
Console.WriteLine("Bar");
goto case "bar";
}
```

We get (which is likely 'correct'):

```csharp
string test = "hello";
string text = test;
if (text != null)
{
if (!(text == "hello"))
{
if (!(text == "bar"))
{
if (text == "baz")
{
Console.WriteLine("Bar");
return;
}
if (!(text == "frob"))
{
return;
}
Console.WriteLine("Bar");
}
}
else
{
Console.WriteLine("Foo");
}
Console.WriteLine("Bar");
}
```

For the `goto` example decompile `System.Web.Mvc.Html.InputExtensions::InputHelper` from System.Web.Mvc (Version 3.0.0.0).