Open Meir017 opened 3 months ago
consider the following code:
public void Method(List<int> list) { // should trigger the analyzer foreach (var item in list) { Console.WriteLine(item); } list.ForEach(Console.WriteLine); // the suggested fix foreach (var item in CollectionsMarshal.AsSpan(list)) { Console.WriteLine(item); } }
Iterating over List without getting the span first.
ForEach
List<T>
my current solution for List<T>.ForEach is using the https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.BannedApiAnalyzers/Microsoft.CodeAnalysis.BannedApiAnalyzers.md and banning the List<T>.ForEach and having a comment suggesting to use our extension method ForEachSpan which gets the span from the list and then iterates over the list
List<T>.ForEach
ForEachSpan
💠I'm not sure the gains for this are worth giving up the _version check.
_version
consider the following code:
Iterating over List without getting the span first.
Describe suggestions on how to achieve the rule
ForEach
method on when the target isList<T>
List<T>
my current solution for
List<T>.ForEach
is using the https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.BannedApiAnalyzers/Microsoft.CodeAnalysis.BannedApiAnalyzers.md and banning theList<T>.ForEach
and having a comment suggesting to use our extension methodForEachSpan
which gets the span from the list and then iterates over the list