When the extension method call cannot be written without type arguments (another extension method with the same name and a different arity is found first), the call falls back to the static form. For 'a?.M()' that fallback produced 'Enumerable.Count(s?)', which is not valid C#. Writing the type arguments excludes the extension methods of a different arity, so for a null-conditional target the type arguments are tried before giving up.
32 lines
575 B
C#
32 lines
575 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue3180
|
|
{
|
|
internal static class Extensions
|
|
{
|
|
public static int Count(this IEnumerable source)
|
|
{
|
|
return 5;
|
|
}
|
|
}
|
|
|
|
internal class NullConditional
|
|
{
|
|
public static int StaticCall(IEnumerable<string> s)
|
|
{
|
|
return Enumerable.Count(s);
|
|
}
|
|
|
|
public static int CountOrZero(IEnumerable<string> s)
|
|
{
|
|
#if EXPECTED_OUTPUT
|
|
return s?.Count<string>() ?? 0;
|
|
#else
|
|
return (s != null) ? Enumerable.Count(s) : 0;
|
|
#endif
|
|
}
|
|
}
|
|
}
|