RefactoringEssentials icon indicating copy to clipboard operation
RefactoringEssentials copied to clipboard

RECS0015 has semantic consequences

Open jnyrup opened this issue 7 years ago • 0 comments
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.

jnyrup avatar Jan 02 '18 13:01 jnyrup