mirror of
https://github.com/haven1433/HexManiacAdvance.git
synced 2026-10-02 05:06:35 -05:00
make an extension method for List.Sort that works the way
I expected it to - taking a sorting lambda
This commit is contained in:
@@ -60,7 +60,7 @@
|
||||
<Compile Include="Models\PokemonModel.cs" />
|
||||
<Compile Include="Models\SearchByte.cs" />
|
||||
<Compile Include="Models\StoredMetadata.cs" />
|
||||
<Compile Include="NumericExtensions.cs" />
|
||||
<Compile Include="SystemExtensions.cs" />
|
||||
<Compile Include="Models\Enums.cs" />
|
||||
<Compile Include="Models\IFileSystem.cs" />
|
||||
<Compile Include="Models\LoadedFile.cs" />
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace HavenSoft.HexManiac.Core {
|
||||
public static class NumericExtensions {
|
||||
public static class SystemExtensions {
|
||||
public static T LimitToRange<T>(this T value, T lower, T upper) where T : IComparable<T> {
|
||||
if (upper.CompareTo(lower) < 0) throw new ArgumentException($"upper value {upper} is less than lower value {lower}");
|
||||
if (value.CompareTo(lower) < 0) return lower;
|
||||
if (upper.CompareTo(value) < 0) return upper;
|
||||
return value;
|
||||
}
|
||||
public static void Sort<T>(this List<T> list, Func<T,T,int> compare) {
|
||||
list.Sort(new StubComparer<T> { Compare = compare });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -548,7 +548,7 @@ namespace HavenSoft.HexManiac.Core.ViewModels {
|
||||
}
|
||||
|
||||
// reorder the list to start at the current cursor position
|
||||
results.Sort(new StubComparer<(int start, int end)> { Compare = (x, y) => x.start.CompareTo(y.start) });
|
||||
results.Sort((a, b) => a.start.CompareTo(b.start));
|
||||
var offset = scroll.ViewPointToDataIndex(SelectionStart);
|
||||
var left = results.Where(result => result.start < offset);
|
||||
var right = results.Where(result => result.start >= offset);
|
||||
|
||||
Reference in New Issue
Block a user