I have seen in the forum several cases where people get a false positive hint or warning that 'Expression is always false/true'. Well, I found another one. I have a custom Comparer-class that implements the IComparer<T>-interface, which has only a single method to implement: CompareTo(T x, T y) : int. In my case, T is a reference type, and following .NET's documentation, I first check the cases where either x or y are null. However, ReSharper keeps telling me that neither x nor y could ever be null:
public int Compare(Shift x, Shift y)
if (x == y) return 0;
if (x == null) return -1;
if (y == null) return 1;
int startTimeComparison = x.StartTime.CompareTo(y.StartTime);
return startTimeComparison == 0
If I omit the checks, FxCop tells me to 'validate my public method's arguments', which I feel is a valid point in this case (not in the least because null-values are valid values when it comes to sorting). So why is ReSharper giving me this message?
I'm using running VS2010 with R# 18.104.22.168 installed.