-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Open
Labels
Description
Input code
using System;
class IncompleteSwitchExpressionTest
{
static int Test(StringComparison c)
{
return c switch {
StringComparison.Ordinal => 0,
StringComparison.OrdinalIgnoreCase => 1,
};
}
}
Erroneous output
internal class IncompleteSwitchExpressionTest
{
private static int Test(StringComparison c)
{
switch (c)
{
case StringComparison.Ordinal:
return 0;
case StringComparison.OrdinalIgnoreCase:
return 1;
default:
{
global::<PrivateImplementationDetails>.ThrowSwitchExpressionException(c);
int result = default(int);
return result;
}
}
}
}
When a switch expression does not specify a default case the compiler will add one that throws a SwitchExpressionException
or a InvalidOperationException
on older runtimes.
The decompiled code cannot recompile as <PrivateImplementationDetails>
is not a valid identifier.
Details
- Product in use: ILSpy 9.0 VS extension