icsharpcode/ILSpy — pull request #413 by kg (2013-07-22 07:24:23+00:00)
Title: Handle switch cases in the form 'default: case x:'

This introduces a simple fixup pass after ILSwitch nodes are constructed that identifies scenarios where the right form for a switch case is 'default: case x: case y: ...'. It then folds the default case into the case it normally jumps to.

As a result, to tell whether a case block is default you now check case.IsDefault instead of checking to see if it has any values.

This makes it possible for decompiled code involving switches to not need gotos in some scenarios, like in the following simple test case:

```csharp
using System;

public static class Program {
public static int DBF;

internal static void ApplyState () {
if (false) {
} else {
Console.WriteLine("Entered");

int func;

switch (DBF) {
default:
case 0:
Console.WriteLine("Default case");
func = 0;
break;
case 1:
Console.WriteLine("case 1");
func = 1;
break;
case 2:
Console.WriteLine("case 2");
func = 2;
break;
case 3:
Console.WriteLine("case 3");
func = 3;
break;
}

Console.WriteLine("Tail");
}

Console.WriteLine("Exited");
}

public static void Main (string[] args) {
DBF = 0;
ApplyState();
DBF = 2;
}
}
```