RefactoringEssentials
RefactoringEssentials copied to clipboard
RECS0015 has semantic consequences
trafficstars
Take this snippet of code.
public static bool SequenceEqual<TSource>(
this IEnumerable<TSource> first,
IEnumerable<TSource> second,
IEqualityComparer<TSource> comparer = null)
{
if (first is ICollection<TSource> firstCollection
&& second is ICollection<TSource> secondCollection
&& firstCollection.Count != secondCollection.Count)
{
return false;
}
return Enumerable.SequenceEqual(first, second, comparer);
}
RECS0015 suggests that
Enumerable.SequenceEqual(first, second, comparer)
should be replaced with
first.SequenceEqual(second, comparer)
But that is semantically different as the replaced method call now calls itself instead of System.Linq.Enumerable.SequenceEqual.