diff --git a/BizHawk.Client.Common/tools/RamSearchEngine/RamSearchEngine.cs b/BizHawk.Client.Common/tools/RamSearchEngine/RamSearchEngine.cs index 4329491533..732824ce39 100644 --- a/BizHawk.Client.Common/tools/RamSearchEngine/RamSearchEngine.cs +++ b/BizHawk.Client.Common/tools/RamSearchEngine/RamSearchEngine.cs @@ -313,54 +313,31 @@ namespace BizHawk.Client.Common.RamSearchEngine switch (column) { case WatchList.ADDRESS: - if (reverse) + if (!reverse) { - _watchList = _watchList.OrderByDescending(w => w.Address).ToList(); - } - else - { - _watchList = _watchList.OrderBy(w => w.Address).ToList(); _isSorted = true; } + _watchList = _watchList.OrderBy(w => w.Address, reverse).ToList(); break; case WatchList.VALUE: - _watchList = reverse - ? _watchList.OrderByDescending(w => GetValue(w.Address)).ToList() - : _watchList.OrderBy(w => GetValue(w.Address)).ToList(); - + _watchList = _watchList.OrderBy(w => GetValue(w.Address), reverse).ToList(); break; case WatchList.PREV: - _watchList = reverse - ? _watchList.OrderByDescending(w => w.Previous).ToList() - : _watchList.OrderBy(w => w.Previous).ToList(); - + _watchList = _watchList.OrderBy(w => w.Previous, reverse).ToList(); break; case WatchList.CHANGES: if (_settings.IsDetailed()) { - if (reverse) - { - _watchList = _watchList - .Cast() - .OrderByDescending(w => w.ChangeCount) - .Cast().ToList(); - } - else - { - _watchList = _watchList - .Cast() - .OrderBy(w => w.ChangeCount) - .Cast().ToList(); - } + _watchList = _watchList + .Cast() + .OrderBy(w => w.ChangeCount, reverse) + .Cast().ToList(); } break; case WatchList.DIFF: - _watchList = reverse - ? _watchList.OrderByDescending(w => GetValue(w.Address) - w.Previous).ToList() - : _watchList.OrderBy(w => GetValue(w.Address) - w.Previous).ToList(); - + _watchList = _watchList.OrderBy(w => GetValue(w.Address) - w.Previous, reverse).ToList(); break; } } diff --git a/BizHawk.Common/Extensions/CollectionExtensions.cs b/BizHawk.Common/Extensions/CollectionExtensions.cs index e6b39522f1..7b2ae2d63f 100644 --- a/BizHawk.Common/Extensions/CollectionExtensions.cs +++ b/BizHawk.Common/Extensions/CollectionExtensions.cs @@ -2,11 +2,20 @@ using System; using System.Collections.Generic; +using System.Linq; namespace BizHawk.Common.CollectionExtensions { public static class CollectionExtensions { + public static IOrderedEnumerable OrderBy( + this IEnumerable source, + Func keySelector, + bool desc) + { + return desc ? source.OrderByDescending(keySelector) : source.OrderBy(keySelector); + } + public static int LowerBoundBinarySearch(this IList list, Func keySelector, TKey key) where TKey : IComparable { int min = 0;