mirror of
https://github.com/github/codeql.git
synced 2026-03-27 01:38:22 +01:00
123 lines
2.1 KiB
C#
123 lines
2.1 KiB
C#
using System;
|
|
|
|
class Switch
|
|
{
|
|
void M1(object o)
|
|
{
|
|
switch (o) { }
|
|
}
|
|
|
|
void M2(object o)
|
|
{
|
|
switch (o)
|
|
{
|
|
case "a":
|
|
return;
|
|
case 0:
|
|
throw new Exception();
|
|
case null:
|
|
goto default;
|
|
case int i:
|
|
if (o == null)
|
|
return;
|
|
goto case 0;
|
|
case string s when s.Length > 0 && s != "a":
|
|
Console.WriteLine(s);
|
|
return;
|
|
case double d when Throw():
|
|
Label:
|
|
return;
|
|
default:
|
|
goto Label;
|
|
}
|
|
}
|
|
|
|
void M3()
|
|
{
|
|
switch (Throw())
|
|
{
|
|
default:
|
|
return;
|
|
}
|
|
}
|
|
|
|
void M4(object o)
|
|
{
|
|
switch (o)
|
|
{
|
|
case int _:
|
|
break;
|
|
case bool _ when o != null:
|
|
break;
|
|
}
|
|
}
|
|
|
|
void M5()
|
|
{
|
|
switch (1 + 2)
|
|
{
|
|
case 2 :
|
|
break;
|
|
case 3 :
|
|
break;
|
|
}
|
|
}
|
|
|
|
void M6(string s)
|
|
{
|
|
switch ((object)s)
|
|
{
|
|
case int _ :
|
|
break;
|
|
case "" :
|
|
break;
|
|
}
|
|
}
|
|
|
|
bool M7(int i, int j)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 1 :
|
|
return true;
|
|
case 2 :
|
|
if (j > 2)
|
|
break;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool M8(object o)
|
|
{
|
|
switch (o)
|
|
{
|
|
case int _ :
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
int M9(string s)
|
|
{
|
|
switch (s?.Length)
|
|
{
|
|
case 0 : return 0;
|
|
case 1 : return 1;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
static bool Throw() => throw new Exception();
|
|
|
|
int M10(string s)
|
|
{
|
|
switch (s.Length)
|
|
{
|
|
case 3 when s=="foo" : return 1;
|
|
case 2 when s=="fu" : return 2;
|
|
}
|
|
return -1;
|
|
}
|
|
}
|