if (ReferenceEquals(actual, expected)) //check if are the same or both null
{
return true;
}
if (actual == null || expected == null) //cheks if any of them is null
{
return false;
}
//At this point neither actual or expected can be null.
if (actual.Count != expected.Count)
SonarQube complains about ‘actual’ or ‘expected’ could be null here in the last if, which is not possible.
According to MSDN:
https://docs.microsoft.com/en-us/dotnet/api/system.object.referenceequals?view=netframework-4.7.1
public static bool ReferenceEquals (object objA, object objB);
true
if objA
is the same instance as objB
or if both are null ; otherwise, false
.