The following code snippet triggers CA1860 analyzer diagnostic and the code fix is enabled:
record Foo(ICollection<string> List);
Foo foo = null;
if (foo?.List.Any() == true) // CA1860 with code fix
{
Console.WriteLine("oops");
}
// does not print anything
The code fix changes the snippet to this and breaks the existing behaviour:
record Foo(ICollection<string> List);
Foo foo = null;
if (foo?.List.Count != 0 == true)
{
Console.WriteLine("oops");
}
// prints "oops"
The code fix should not be offered in case above, as it introduces a breaking change. Interestingly, the code fix is already not provided when the null propagation is used on the collection variable directly:
ICollection<string> list = null;
if (list?.Any() == true) // CA1860 with no code fix
{
Console.WriteLine("oops");
}