private static int CompareLineTexts(SledFindResultsType findResult1, SledFindResultsType findResult2) { return string.Compare( findResult1.LineText, findResult2.LineText, StringComparison.OrdinalIgnoreCase); }
private static int CompareLines(SledFindResultsType findResult1, SledFindResultsType findResult2) { return findResult1.Line == findResult2.Line ? 0 : findResult1.Line < findResult2.Line ? -1 : 1; }
private static int CompareFiles(SledFindResultsType findResult1, SledFindResultsType findResult2) { return string.Compare( s_bShowFileNamesOnly ? findResult1.Name : findResult1.File, s_bShowFileNamesOnly ? findResult2.Name : findResult2.File, StringComparison.OrdinalIgnoreCase); }
/// <summary> /// Compare two find results /// </summary> /// <param name="x">First result</param> /// <param name="y">Second result</param> /// <param name="column">Column of result</param> /// <param name="order">SortOrder</param> /// <returns>Less than zero: x is less than y. Zero: x equals y. Greater than zero: x is greater than y.</returns> public static int Compare(SledFindResultsType x, SledFindResultsType y, int column, SortOrder order) { int result; switch (column) { default: { result = CompareFiles(x, y); if (result == 0) result = CompareLines(x, y); if (result == 0) result = CompareLineTexts(x, y); } break; case 1: { result = CompareLines(x, y); if (result == 0) result = CompareFiles(x, y); if (result == 0) result = CompareLineTexts(x, y); } break; case 2: { result = CompareLineTexts(x, y); if (result == 0) result = CompareFiles(x, y); if (result == 0) result = CompareLines(x, y); } break; } if (order == SortOrder.Descending) result *= -1; return result; }