ILSpy icon indicating copy to clipboard operation
ILSpy copied to clipboard

Improve pattern match for generic

Open CreateAndInject opened this issue 4 years ago • 0 comments

        static void Test<T>(T a)
        {
            if (a is int x)
                Console.WriteLine(x);
        }

ILSpy:

private static void Test<T>(T a)
{
	if (a is int)
	{
		object obj = a;
		int x = (int)((obj is int) ? obj : null);
		if (true)
		{
			Console.WriteLine(x);
		}
	}
}

CreateAndInject avatar Jan 19 '22 17:01 CreateAndInject