/// <summary> /// What we need to do is find a *repeatable* arbitrary way to choose between /// two errors; we can for example simply take the one that is lower in alphabetical /// order when converted to a string. As an optimization, we compare error codes /// first and skip string comparison if they differ. /// </summary> private static int CanonicallyCompareDiagnostics(Diagnostic x, Diagnostic y) { ErrorCode xCode = (ErrorCode)x.Code; ErrorCode yCode = (ErrorCode)y.Code; int codeCompare = xCode.CompareTo(yCode); // ToString fails for a diagnostic with an error code that does not prevernt successful delegate conversion. // Also, the order doesn't matter, since all such diagnostics will be dropped. if (!ErrorFacts.PreventsSuccessfulDelegateConversion(xCode) || !ErrorFacts.PreventsSuccessfulDelegateConversion(yCode)) { return(codeCompare); } // Optimization: don't bother return(codeCompare == 0 ? string.CompareOrdinal(x.ToString(), y.ToString()) : codeCompare); }