The ananalyzer reports S1905 if an collection of nullable objects is filtered into a collection of non-nullable objects, although that has two effects:
-
removes all null elements,
-
changes the resulting type.
public static void TestOfType() { var test = new string?[] { "one", "two", null, "three" }; Console.WriteLine(string.Join(", ", test)); Console.WriteLine(string.Join(", ", test.OfType<string>())); }
The code above raises a S1905 on the OfType() call, although the call is clearly making a different. The resulting output is:
one, two, , three
one, two, three
The analyzer version is 8.4.0.15306